If I do
alert(new Date(1313690400000))
returns: Thu Aug 18 2011 13:00:00 GMT-0500 (CDT)
however, PHP
echo date('Y-m-d H:i:s', 1313690400000);
returns: 1951-12-14 05:50:24
JavaScript uses milliseconds as a timestamp, whereas PHP uses seconds. As a result, you get very different dates, as it is off by a factor 1000.
So remove three zeroes at the PHP side:
echo date('Y-m-d H:i:s', 1313690400);
Javascript Date is milliseconds since Epoch, whereas PHP date uses unix timestamp which is in seconds.
So to get the same date in php, divide by 1000 first
PHP's date/time functions use the number of seconds since the epoch, while Javascript uses the number of milliseconds. In your php func:
echo date('Y-m-d', 1313690400000 / 1000);
Related
I have this timestamp how to convert it to unix timestamp
1.6749018E+12
Or is there any way to decode it in PHP let me know.
have good day!
My code
$t = '1.6749018E+12';
print date('H:i:s', $t);
Not work!
1.6749018E+12 looks like a unix time with milliseconds as float number. If I'm right, then the conversion to a unix time in seconds is:
$unixtime = intval($NUMBER/1000)
where $NUMBER is the input number (1.6749018E+12 in you example). This number represents: Sat Jan 28 11:30:00 CET 2023 (or 10:30 UTC).
$dayBasedOnUTC = date('l', $_GET['day']);
Why is it that when I echo the value of $dayBasedOnUTC the day returned is a Tuesday?
The UTC value of $_GET['day'] is: 1409393126144
If you put that number into any Unix Timestamp Converter you will see the date is Saturday.
It appears that 1409393126144 is a Javascript timestamp, which is counted in milliseconds. PHP expects its UNIX timestamps in seconds though. So 1409393126144 to PHP is a timestamp in the far future.
Divide by 1000 to get the correct value:
echo date('l', 1409393126144 / 1000);
Hello i need to get this date value from php 1328569380 and convert it to javascript date.
By the way how is this date "1328569380" type of form called ?
The numeric date time your are referring to is called a timestamp. It is the number of seconds elapsed since january 1st of 1970 if i'm not wrong.
To send a date to javascript, just print it out using the timestamp x 1000 since it also accepts millisecond initialization format:
mydate = new Date(<?php echo $mytimestamp*1000; ?>);
Good luck
This is a Unix epoch timestamp. See the following thread for the how-to:
Convert a Unix timestamp to time in JavaScript
Your value is the number of seconds that has passed since 1970-01-01 00:00:00, called the Unix epoch.
JavaScript counts the number of milliseconds instead, thus you have to multiply your timestamp with 1000 prior to using it to create a JavaScript date-object.
var phptimestamp = 1328569380;
var date = new Date(phptimestamp * 1000);
I am new to PHP and am writing a PHP script that contains a module which reads the file timestamp out of a file and then compare with system time to see whether the file is older than 5 minutes or not and I am wondering how that can be achieved. I am currently using
$timeStamp = strftime('%c', filectime($this->localPath));
$timeStamp2 = filectime($this->localPath);
The two $timeStamp and $timeStamp2 are different, the 1st one is more human readable
$timeStamp Mon Jun 20 15:17:01 2011
$timeStamp2 1308608221
What does $timeStamp2 mean?
And again, how to see if the file is more than 5 minutes old?
That is Unix timestamp actually (seconds since 1st jan 1970 or EPOCH)
You can use time() function to get current time in same Unix format.
And then subtract both time values to check whether difference is > 300 (5 min) or not.
$timeStamp2 is a UNIX timestamp (the number of seconds passed since 01/01/1970).
You can get the same thing from $timeStamp1 by doing
$timeStamp1 = strtotime($timeStamp1)
and then compare the two values
Answering your question "What does $timeStamp2 mean?"
1308608221 is the number of seconds that have passed since midnight January 1,1970.
I am being returned this time format from an API:
1287498792000
Can anyone advise what format that is and how I would parse it in PHP?
This format is the Number of milliseconds since 1970-01-01.
Your date represents 2010-10-19 # 14h33 if i'm not mistaken.
Just divide it by 1000 and use the standard php functions for unix timestamps like date to display it or getdate to extract the different parts.
It's a Unix timestamp represented in milliseconds — equivalent to the return value from time() multiplied by 1,000 (timestamp in PHP are in seconds, not milliseconds).
You can use it directly1 in PHP, e.g. for the date() function:
print date('l jS \of F Y h:i:s A', 1287498792000 / 1000);
// Outputs: Tuesday 19th of October 2010 02:33:12 PM
EDIT
1 Yes, it seems to be in milliseconds. Divide by 1,000 in order to get a timestamp that PHP understands.
It's a UNIX timestamp - it represents the count of seconds since January 1st, 1970.
You can use PHP's date() function to convert it to a human readable format.