将“yyyy-mm-dd”日期格式化为“dd月yyyy”(Format a “yyyy-mm-dd” date into “dd month yyyy”)
我在我的程序中有一个变量,以2018-04-21的形式存储日期。 现在,我应该如何将价值改变成像2018年4月21日这样的东西?
我需要这样的东西:
var date = stringifyTheDate(actual_date);我应该在stringifyTheDate函数中包含哪些内容?
I have a variable in my program that stores the date in the form of 2018-04-21. Now, how do I change the value into something like 21st April, 2018?
I need something like:
var date = stringifyTheDate(actual_date);What should I include in the stringifyTheDate function to do that?
最满意答案
如果你正在使用Moment.js ,你可以这样做。
console.log(moment("2018-04-21").format("DD MMMM YYYY")); //prints 21 April, 2018MomentJs是日期和时间广泛使用的库,如果你不使用它,那么这是你如何添加它
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script&t;If you are using Moment.js this how you do it.
console.log(moment("2018-04-21").format("DD MMMM YYYY")); //prints 21 April, 2018MomentJs is widely used library for date and time, if you are not using it then this is how you add it
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>更多推荐
发布评论