最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Need help formatting a date in MomentJS in Japanese - Stack Overflow

programmeradmin4浏览0评论

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

,console

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./caganaveci/edit?js,console

Share Improve this question edited Jan 1, 2019 at 11:26 Bhargav Rao 52.3k29 gold badges127 silver badges141 bronze badges asked Nov 7, 2017 at 10:36 user2296208user2296208 1032 silver badges6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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./ajax/libs/moment.js/2.19.1/moment-with-locales.min.js"></script>
</body>
</html>

Just as an alternative, there is also toLocaleString:

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

发布评论

评论列表(0)

  1. 暂无评论