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

标签 javascript date datetime type-conversion

我是新手,想要将 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/

相关文章:

mysql - 日期时间比较?

javascript - javascript中两次百分比之间的差异

javascript - Puppeteer 打开 URL 时超时

java - 如何将日期格式转换为mysql日期格式?

javascript - 当填写超过 2 个字符时添加第二个输入。 (javascript)(很难)

c# - 日本的完整日期时间产生问号

javascript - Chrome Javascript 日期构造函数错误?

javascript - 如何在 Javascript 中使用 toISOString()?

javascript - KineticJS:如何获取 Sprite 或图像的宽度和高度?

javascript onload 循环中的事件