admin管理员组文章数量:1201603
I am using the next code to convert a date received from a MySQL database format 1993-10-23 00:00:00
and display it in spanish:
alert(moment('1993-10-23 00:00:00', 'YYYY-MM-DD', 'es'));
23 oct is saturday. I would expect to get sábado
but I get the next:
Sat Oct 23 1993 00:00:00 GMT+0200
Also tried adding: moment.locale('es-ES');
, moment.locale('en-ES');
and moment.locale('es');
but neither works.
What's the correct way of converting dates from a language to another?
I am using the next code to convert a date received from a MySQL database format 1993-10-23 00:00:00
and display it in spanish:
alert(moment('1993-10-23 00:00:00', 'YYYY-MM-DD', 'es'));
23 oct is saturday. I would expect to get sábado
but I get the next:
Sat Oct 23 1993 00:00:00 GMT+0200
Also tried adding: moment.locale('es-ES');
, moment.locale('en-ES');
and moment.locale('es');
but neither works.
What's the correct way of converting dates from a language to another?
Share Improve this question edited Jun 15, 2015 at 10:13 Alpha2k asked Jun 15, 2015 at 10:08 Alpha2kAlpha2k 2,2417 gold badges43 silver badges67 bronze badges 3- 1 You're using the syntax for parsing a string, not outputting it. You want moment().format(). Be careful with ISO 8601 like formats without a timezone, they are treated differently by ES5 (UTC) and ES6 (local). – RobG Commented Jun 15, 2015 at 10:23
- @RobG thanks, check the answer, is there anything to add for the ISO format ? – Alpha2k Commented Jun 15, 2015 at 10:32
- ISO 8601 says that dates with a missing timezone should be treated as local, whereas ES5 says to treat them as UTC. ES6 changes to be consistent with ISO. To be sure, you should use '1993-10-23T00:00:00Z' if you want it treated as UTC. Add the required timezone if you want something else and parse it with Moment.js (or write your own 2 or 3 line function). The Javascript parse will only parse ISO 8601 UTC. – RobG Commented Jun 15, 2015 at 10:56
2 Answers
Reset to default 17This seems to work, thanks @RobG
var localLocale = moment('1993-10-23 00:00:00');
moment.locale('es');
localLocale.locale(false);
alert(localLocale.format('LLLL'));
The following method worked for me
moment(agreement.dateStart).locale('es').format('LLLL')
本文标签: javascriptMomentJS time in spanishStack Overflow
版权声明:本文标题:javascript - MomentJS time in spanish - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738541932a2095664.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论