javascript - Check if date match with format using momentjs -


i try check if date match format using momentjs. have error when date include time zone.

example:

moment('mon nov 10 2016 14:53:17', 'ddd mmm dd yyyy hh:mm:ss', true).isvalid()  

in case response true without errors. in other case, not found correct date format compare

moment('mon nov 10 2016 14:53:17 gmt-0500 (ect)', '?????', true).isvalid()  

you can split string in gtm-.. place , take part before. below example, split() splitting string , return array, first part of string (before gtm) @ 0 index.

var data = 'mon nov 10 2016 14:53:17 gmt-0500 (ect)'; moment(date.split(' gmt')[0], 'ddd mmm dd yyyy hh:mm:ss', true).isvalid()  

it works strings without gtm part too, because return one-element array whole string.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -