简体   繁体   中英

Converting a date from one language to another

I have a date in Thai as:

31มี.ค.2017, 16:56:51

which translates to

Mar 31, 2017, 16:56:51

using google translate. Is there a way, I could do this using momentjs locale support? If not, is there any other way out?

Momentjs suports i18n and supports Thai [th] locale, you can parse your input using moment(String, String, String) .

Then you can use locale() and format() to show the value using english locale.

Here a working sample:

 var m = moment('31มี.ค.2017, 16:56:51', 'DDMMMMYYYY, HH:mm:ss', 'th'); console.log(m.locale('en').format('MMM DD, YYYY, HH:mm:ss')); // Mar 31, 2017, 16:56:51 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM