Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Datepicker Set Value As Epoch Time

I use a data picker like that:

$('#startTime').datepicker("option", "dateFormat", 'yy-mm-dd ');

However when I want to set it I have a epoch time value that comes from my server (milliseconds since the standard base time January 1, 1970) How can I do that when I set it like this it just shows a number instead of date as usual?

like image 645
kamaci Avatar asked Nov 27 '11 21:11

kamaci


2 Answers

$('#startTime').datepicker("option", "dateFormat", '@');

@ sets the format to UNIX timestamp -> http://docs.jquery.com/UI/Datepicker/formatDate
Please note: This is in milliseconds, not seconds

like image 71
Manse Avatar answered Nov 05 '22 17:11

Manse


$(function()
{
    $("input[type='text']")
        .datepicker({ dateFormat: '@' })
        .change( function(){ this.value = parseInt(this.value,10)/1000; });
});

this is what I did to get the seconds vs. ms from the datepicker

like image 40
artfulhacker Avatar answered Nov 05 '22 16:11

artfulhacker