javascript - Momentjs: Parse format like 'MM/DD/YYYY hmA' doesn't work -


i have date string , try parse use moment.js:

var d = '06/09/2015 200am'; var date = moment(d, 'mm/dd/yyyy hmma'); 

however, hour seems not right after parsing:

console.error(date.hours); //output: 20 

am doing wrong here?

i guess if hour , minute separated ':' solve problem, time value of , don't put ':' in it..

thanks help.

that's odd string format, 1 expect reliable 2 digits hour value. think you're going have pre-process it.

var d = /*...get string wherever...*/; var r = /^(\d{2}\/\d{2}\/\d{4}) (\d{3}..)$/ var m = r.exec(d); if (m) {     d = m[1] + " 0" + m[2]; } var date = moment(d, 'mm/dd/yyyy hmma'); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -