What is the PHP equivalent of the Javascript Date.UTC command?

How can I say this Javascript in PHP:

var ts=Date.UTC(1985,1,22); 
+4
source share
3 answers

PHP online docs are very useful: http://www.php.net/manual/en/ref.datetime.php

mktime accepts the arguments hour , minute , second , month , day , year .

 $ts = mktime(0, 0, 0, 1, 22, 1985); 

Date.UTC returns milliseconds, while mktime returns seconds, so if you still need milliseconds, multiply them by 1000.

+8
source
 $date = new DateTime(NULL, new DateTimeZone('UTC')); $date->setDate(1985, 1, 22); $ts = $date->getTimestamp(); 

EDIT: Fixed time zone setting.

+6
source
 $ts = gmmktime(0, 0, 0, 2, 22, 1985) * 1000 
0
source

All Articles