View Full Version : how to convert date to unixtine in JS

05-21-2008, 06:29 AM
hi ,

i have date in (21 May 2008) this format.

What is the function in JS to convert to unix time
In php it was

strtotime("21 May 2008")

what is the function in JS

05-21-2008, 06:46 AM
var D=new Date(Date.parse("21 May 2008"))
// returns Date object

var T=Date.parse("21 May 2008")
// returns javascript timestamp in milliseconds (not seconds)

alert(T+'\n'+ D.toLocaleDateString())

05-21-2008, 07:06 AM
It is not showing the correct time , iwant may 21 2008 00.00 time

05-21-2008, 07:06 AM
It shows 1211353200 which is 5/21/2008 4:30:00 PM

Which time zone does JS follows

Philip M
05-21-2008, 09:25 AM
You cannot extract a time when only a date DD/MM/YYYY is provided.

If you want the current time HH:MM;SS then:

<script type="text/javascript">

var d = new Date();
var yy = d.getYear();
var mm = d.getMonth()+1;
var dd = d.getDate();
var hh = d.getHours();
var mn = d.getMinutes();
var ss = d.getSeconds();
var fd = dd+ "/"+ mm +"/" + yy + " " + hh + ":" + mn + ":" + ss
alert (fd);


If you have the time, then:

var d=new Date(Date.parse("21 May 2008 10:03:20"));

Javascript takes its time from the user's computer, that is local time. You can use UTC time (= GMT) if you wish, with an offset if desired.

Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
A. One thousand