admin管理员组文章数量:1387463
I'm trying to convert a simple string to a unix timestamp using moment.js
moment('2014-01-14 07:25 PM').unix();
moment('2014-01-14 07:25 AM').unix();
The problem is I get the same result with AM or PM in that string.
1389684300
What gives?
I'm trying to convert a simple string to a unix timestamp using moment.js
moment('2014-01-14 07:25 PM').unix();
moment('2014-01-14 07:25 AM').unix();
The problem is I get the same result with AM or PM in that string.
1389684300
What gives?
Share Improve this question asked Jan 14, 2014 at 0:29 ShealanShealan 1,3463 gold badges20 silver badges34 bronze badges 1- I had the same question but needed to convert to ISO string. The solution by @Pekka worked great for me. – Ryan Conaway Commented Oct 4, 2014 at 16:39
2 Answers
Reset to default 6The docs make no mention that your specified format is guaranteed to be correctly recognized. It says
Warning: Browser support for this is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.`
You should probably explicitly specify a format in the second argument.
This should work (JSFiddle):
moment('2014-01-14 07:25 PM', 'YYYY-MM-DD hh:mm A').unix();
It seems to have been a bug in version 2.0.0. Updating to 2.5.0 and the problem is fixed.
本文标签: javascriptConverting simple datetime string in momentjs doesn39t detect AMPMStack Overflow
版权声明:本文标题:javascript - Converting simple datetime string in moment.js doesn't detect AMPM - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744549974a2612124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论