How can I use PHP to get a UNIX timestamp like what I get from the JS method .getTime()
? I seem to be having trouble since .getTime()
returns milliseconds. I know I have to convert the timestamps first for JS to read it, but how can I do this?
Edit:
Agreed with the multiply by 1000, but why do I get this?:
timestamp: 1305593400
timestamp * 1000: 1.3055934E+12
timestamp: 1305612420
timestamp * 1000: 1.30561242E+12
timestamp: 1305635400
timestamp * 1000: 1.3056354E+12
timestamp: 1304901960
timestamp * 1000: 1.30490196E+12
timestamp: 1304944620
timestamp * 1000: 1.30494462E+12
A simple solution is to get the timedelta object by finding the difference of the given datetime with Epoch time, i.e., midnight 1 January 1970. To obtain time in milliseconds, you can use the timedelta. total_seconds() * 1000 .
Timestamps in milliseconds and other units. Timezones, Unix timestamps in milliseconds & UTC.
Unix is an operating system originally developed in the 1960s. Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.
=(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number). For other time zones: =((A1 +/- time zone adjustment) / 86400) + 25569.
UNIX timestamps are in seconds. Multiply by 1000.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With