简体   繁体   中英

Need help formatting a date in MomentJS in Japanese

I need help formatting a date in MomentJS

The main issue i am facing is that the Japanese “day” character is not displaying

  • Date: 3 Nov .
  • Actual Output: 11月 03
  • Expected Output: 11月 03日

Format tried MMM DD

https://jsbin.com/caganaveci/edit?js,console

Solution

The format argument should be MMM Do to append to the day of month. is the ordinal for the day of month.

 moment.locale('ja'); console.log(moment().format('MMM Do')); 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> </head> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment-with-locales.min.js"></script> </body> </html> 

作为替代方案,还有toLocaleString

 console.log(new Date(2017,10,3).toLocaleString('ja',{month:'long',day:'numeric'})); 

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