Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format date in jQuery datetimepicker?

I use jQuery datetimepicker which was extended from jQuery datepicker to pick not only date but time too.

I want to set date/time format this way: dd-mm-yyyy @ hh:mm

$('#timePicker').datetimepicker({   dateFormat: 'dd:mm:yyyy',   separator: ' @ ',   minDate: new Date() }); 

But this does not work. I get date/time in following format:

Thu Jan 27 2011 02:05:17 GMT+0100 

Is there any javascript function to format this date/time? If not how do I do that using the plugin? Check out my code: FIDDLE

like image 754
UpCat Avatar asked Jan 26 '11 07:01

UpCat


People also ask

How do I change the date format from YYYY MM DD in jQuery?

Re: convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript. var tempDate = new Date("2021-09-21"); var formattedDate = [tempDate. getMonth() + 1, tempDate.

How do I change date format in Datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

What is Datetimepicker in jQuery?

Advertisements. Datepickers in jQueryUI allow users to enter dates easily and visually. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.

What is Datetimepicker (); in JS?

The JavaScript DateTime Picker is a lightweight and mobile-friendly control that allows end users to enter or select date and time values from a pop-up calendar and drop-down time list. It provides month, year, and decade views for quick navigation to the desired date.


2 Answers

Here you go.

$('#timePicker').datetimepicker({    // dateFormat: 'dd-mm-yy',    format:'DD/MM/YYYY HH:mm:ss',     minDate: getFormattedDate(new Date()) });  function getFormattedDate(date) {     var day = date.getDate();     var month = date.getMonth() + 1;     var year = date.getFullYear().toString().slice(2);     return day + '-' + month + '-' + year; } 

You need to pass datepicker() the date formatted correctly.

like image 62
Skilldrick Avatar answered Oct 06 '22 21:10

Skilldrick


This works for me. Since it "extends" datepicker we can still use dateFormat:'dd/mm/yy'.

$(function() {     $('.jqueryui-marker-datepicker').datetimepicker({         showSecond: true,         dateFormat: 'dd/mm/yy',       timeFormat: 'hh:mm:ss',       stepHour: 2,       stepMinute: 10,       stepSecond: 10       }); }); 
like image 33
Indrit Kello Avatar answered Oct 06 '22 21:10

Indrit Kello