Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert UNIX timestamp to milliseconds

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
like image 419
MacMac Avatar asked Jun 21 '11 18:06

MacMac


People also ask

How do you convert timestamps to milliseconds?

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 .

Are Unix timestamps in milliseconds?

Timestamps in milliseconds and other units. Timezones, Unix timestamps in milliseconds & UTC.

Are Unix timestamps seconds or milliseconds?

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.

How do I convert Unix time to normal time?

=(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.


1 Answers

UNIX timestamps are in seconds. Multiply by 1000.

like image 150
Ignacio Vazquez-Abrams Avatar answered Sep 26 '22 14:09

Ignacio Vazquez-Abrams