我需要格式化JavaScript日期。我正在使用jQuery Weekcalendar插件,它提供了自己的日期格式。
输入是:
Thu Jan 10 2013 11:15:00 GMT+0100 (CET)
输出应为:
2013-10-01 11:15:00
你可以帮我解决这个问题吗?
答案 0 :(得分:1)
moment.js会有很大帮助
moment().format('YYYY-MM-DD hh:mm:ss'); // for example: 2013-10-01 11:15:00
更新
要将moment.js与现有日期对象一起使用,您需要创建一个包装器
var myDateWrapper = moment(calEvent.start);
console.log(myDateWrapper.format('YYYY-MM-DD hh:mm:ss')) // that's what you want
答案 1 :(得分:0)
看这里您可以使用插件格式化输出。
https://github.com/themouette/jquery-week-calendar/wiki/Date-formating
另见:
https://github.com/themouette/jquery-week-calendar/wiki/Script-options
您需要使用以下选项:
timeFormat:[string |默认值:“h:i a”] - 用于日历显示的时间的格式。 dateFormat:[string |默认值:“M d,Y”] - 用于日历中显示的日期的格式。
修改
$('#calendar').weekCalendar({
dateFormat: 'y.m.d',
timeFormat:"h:i:s"
});