Reputation: 9720
I have date in Javascript
Sun Feb 15 2015 08:02:00 GMT+0200 (EET)
how I can to set in format 'dd/mm/yyyy hh:mm:ss
' into datetime picker?
If I set like this:
dateStart
Sun Feb 15 2015 08:02:00 GMT+0200 (EET)
$('#dateTimeStart').datetimepicker('setDate', dateStart);
Error parsing the date/time string: Missing number at position 10 date/time string = 02-15-2015 08:02:00 timeFormat = HH:mm dateFormat = mm-dd-yyyy
Upvotes: 2
Views: 6930
Reputation: 9720
I change format of date from server in this : '02/15/2015 08:02:00 AM
'
and then I parse this string and create new date:
var dateString ='02/15/2015 08:02:00 AM';
var dateStart = new Date(Date.parse(dateString, "mm/dd/yyyy hh:mm:ss"));
$('#dateTimeStart').datetimepicker('setDate', dateStart);
Upvotes: 0
Reputation: 6031
use below javascript code to change formate
var date = new Date('Sun Feb 15 2015 08:02:00 GMT+0200');
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var fulldate = day+'/'+(month+1)+'/'+year+' '+hours + ':' + minutes.substr(minutes.length-2) + ':' + seconds.substr(seconds.length-2);
see working copy of fiddle
you can create function which return date in format
function convertdate(param){
var date = new Date(param);
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
return fulldate = day+'/'+(month+1)+'/'+year+' '+hours + ':' + minutes.substr(minutes.length-2) + ':' + seconds.substr(seconds.length-2);
}
alert(convertdate('Sun Feb 15 2015 08:02:00 GMT+0200'));
Upvotes: 0
Reputation: 2356
You're looking for a format like
jQuery('#dateTimeStart').datetimepicker({
format:'d/m/Y H:i:s'
});
According to the DateTimePicker documentation at http://xdsoft.net/jqplugins/datetimepicker/, the 'format' string is based on the PHP date format strings, which you can read up on at http://php.net/manual/en/function.date.php. Note in particular they use just one letter to represent multiple numbers (e.g. 'd' instead of 'dd')
Upvotes: 0
Reputation: 36703
$('#dateTimeStart').datetimepicker({
dateFormat: 'yy-dd-mm'
timeFormat: "hh:mm:ss"
});
Upvotes: 1
Reputation: 4560
You have to format date that you have. You can do it with help of function that you can grab here.
Usage:
<script>
document.write($.format.date("Sun Feb 15 2015 08:02:00", "dd/mm/yyyy hh:mm:ss"));
</script>
It's small and really nice solution that can help you to resolve your issue.
Upvotes: 0