将“yyyy

编程入门 行业动态 更新时间:2024-10-26 23:36:28
将“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, 2018

MomentJs是日期和时间广泛使用的库,如果你不使用它,那么这是你如何添加它

<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, 2018

MomentJs 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>

更多推荐

本文发布于:2023-08-03 09:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385229.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:yyyy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!