像$ .datepicker.formatDate这样的函数来格式化时间? [英] Function like $.datepicker.formatDate for formatting time?

查看:507
本文介绍了像$ .datepicker.formatDate这样的函数来格式化时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用$.datepicker.formatDate我只能格式化日期,这意味着如果传递Date对象,则只能格式化日期部分,而不能格式化时间部分.

With $.datepicker.formatDate I can only format a date, meaning if I pass in a Date object, I can only get the date part of it formatted but not the time part.

是否有任何等效的函数可以对时间部分进行格式化/解析,最好使用相同的语法?

Is there any equivalent function which allows the time part to also be formatted/parsed, preferably in the same syntax?

我正在使用以下日期时间插件:

I'm using the following datetime plugin:

https://github.com/eternicode/bootstrap-datepicker

但是它似乎没有我可以使用的等效formatDate函数.

But it doesn't seem to have an equivalent formatDate function that I can use.

推荐答案

日期选择器的 formatDate() 方法没有任何格式设置时间的选项,为此请查看日期时间库,例如 moment.js

The datepicker's formatDate() method does not have any option to format time, for that look at a datetime library like moment.js

Ex

var date = new Date();

var df = moment(date).format('MMMM Do YYYY, h:mm:ss a');
alert(df)

var d = moment('2013-09-11 14:44:03', 'YYYY-MM-DD HH:mm:ss');
console.log(d.format('M/D/YYYY h:m A'))

演示:小提琴

这篇关于像$ .datepicker.formatDate这样的函数来格式化时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆