6

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?

kamaci
  • 72,915
  • 69
  • 228
  • 366
  • 1
    What server are you using ? why cant you format the date to the correct format ? – Manse Nov 27 '11 at 21:43
  • I am getting it from a REST URL and if I format it from my server and decide to change the date format I will have to change the server side code too. However if get it as epoch I can show it at different date formats at different clients. – kamaci Nov 27 '11 at 21:45
  • see my answer - its possible using the UNIX timestamp ( ie MS since 01/01/1970 ) – Manse Nov 27 '11 at 21:46

2 Answers2

8
$('#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

Martijn
  • 15,791
  • 4
  • 36
  • 68
Manse
  • 37,765
  • 10
  • 83
  • 108
  • Just one thing not tobe confused for me. I use Java at my server side. Does getting Java date as long and epoch time are same? I mean one of them calculating seconds and other one milliseconds or same? – kamaci Nov 27 '11 at 21:47
  • @kamaci same as my comment on your question really - what are you using to create the date /time .... add your code to your question then I can tell you – Manse Nov 27 '11 at 21:48
3
$(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

Martijn
  • 15,791
  • 4
  • 36
  • 68
artfulhacker
  • 4,823
  • 1
  • 37
  • 31