If I have a time like 1325982833403 in JavaScript, how do I convert it to a datejs value?

98 views Asked by At

The JavaScript library I'm using represents user login times as long integers:

1325982833403

How do I convert this to a DateTime ('MM/dd/yyyy hh:mm tt') value that the datejs library would understand?

2

There are 2 answers

2
kaz On BEST ANSWER

Using Date constructor:

var date = new Date(1325982833403*1000);

That number is Unix timestamp, google for more information about this, and conversion techniques

0
benastan On

It's a UNIX timestamp; an extremely useful representation of a moment in time.

Unix time, or POSIX time, is a system for describing instants in time, defined as
the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of
Thursday, January 1, 1970 ...

(http://en.wikipedia.org/wiki/Unix_time)

In practice, with this particular library (http://www.datejs.com/), use:

<script src="http://datejs.googlecode.com/files/date.js" type="text/javascript"></script>
<script type="text/javacript">
    var mydate = Date(1325982833403);
</script>