gpt4 book ai didi

javascript将日期和时间转换为特定格式

转载 作者:行者123 更新时间:2023-11-28 07:56:51 26 4
gpt4 key购买 nike

我是新手,想要将 2014-09-25T09:54:00 转换为 9:54 AM Thu, 25th Sep..

有人可以建议我一种用 JavaScript 实现的方法吗?

谢谢

最佳答案

here is a great JavaScript library that handles this very well, and only 5.5kb minified.

http://momentjs.com/

It looks something like this:


moment().format('MMMM Do YYYY, h:mm:ss a'); // February 25th 2013, 9:54:04 am
moment().subtract('days', 6).calendar(); // "last Tuesday at 9:53 AM"
You can also pass in dates as a String with a format, or a Date object.

var date = new Date();
moment(date); // same as calling moment() with no args

// Passing in a string date
moment("12-25-1995", "MM-DD-YYYY");
Also has great support for languages other then English, like, Russian, Japanese, Arabic, Spanish, etc..

关于javascript将日期和时间转换为特定格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25991981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com