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:
But it doesn't seem to have an equivalent formatDate function that I can use.
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./eternicode/bootstrap-datepicker
But it doesn't seem to have an equivalent formatDate function that I can use.
Share Improve this question asked Aug 20, 2013 at 4:06 AliAli 267k268 gold badges591 silver badges785 bronze badges 2- 2 look at moment.js – Arun P Johny Commented Aug 20, 2013 at 4:08
- @ArunPJohny Post a code example, and I can accept! – Ali Commented Aug 20, 2013 at 4:13
1 Answer
Reset to default 6The 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)
and
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'))
Demo: Fiddle