CancelImage Upload

How to return a Unix Timestamp and Micro-Timestamp in PHP

Since the 1st of January 1970 the Unix clock has been ticking, one second at a time. Thanks to this every programmer has one time format from which all the others can be derived. In PHP this timestamp (with the current date, time, etc) can be loaded via the function:

time();

And for the rocket scientists out there who need timestamps that go right down to the microsecond here is the appropriate microtime function:

microtime()

To convert a past date into a Unix timestamp you can use the following function:

$timestamp = mktime(19, 45, 33, 4, 19, 2000);

Results in:

956166333

If you want to return the timestamp in Greenwich Mean Time (GMT) you can use mktime()'s cousin, gmmktime:

$gmtTimestamp = gmmktime(19, 45, 33, 4, 19, 2000);

Results in:

956173533


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com