Javascript Converting human time to timestamp

前端 未结 4 635
面向向阳花
面向向阳花 2020-12-30 07:35

Using javascript, How can I convert a \"human time\" string like \"Wed Jun 20 19:20:44 +0000 2012\" into a timestamp value like \"1338821992\"?

4条回答
  •  情深已故
    2020-12-30 08:02

    Looks like the date/time you've provided is in seconds not milliseconds. So you'll need to divide by 1000 to get the date/time in seconds.

    //Gets date in seconds 
    var d1 = Date.parse('Wed Jun 20 19:20:44 +0000 2012')/1000;
    alert(d1);
    

    Example: http://jsfiddle.net/AUt9K/

提交回复
热议问题