Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  90] [ 3]  / answers: 1 / hits: 37035  / 12 Years ago, thu, february 14, 2013, 12:00:00

I am getting same date time seconds value in JavaScript which is given by strtotime() in PHP. But i need same value in JavaScript.



PHP Code



echo strtotime(2011-01-26 13:51:50);
// 1296046310


JavaScript Code



var d = Date.parse(2011-01-26 13:51:50);
console.log(d);
// 1296030110000

More From » php

 Answers
24

You need to use the same time-zone for a sane comparison:



echo strtotime(2011-01-26 13:51:50 GMT);
// 1296049910

var d = Date.parse(2011-01-26 13:51:50 GMT) / 1000;
console.log(d);
// 1296049910


Update



According to the standard, only RFC 2822 formatted dates are well supported:



Date.parse(Wed, 26 Jan 2011 13:51:50 +0000) / 1000


To generate such a date, you can use gmdate('r') in PHP:



echo gmdate('r', 1296049910);

[#80230] Tuesday, February 12, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnathanhakeems

Total Points: 487
Total Questions: 129
Total Answers: 100

Location: Fiji
Member since Fri, Nov 13, 2020
4 Years ago
;