Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I say this Javascript in PHP:

var ts=Date.UTC(1985,1,22);
like image 280
Joshua Avatar asked Oct 23 '10 04:10

Joshua


3 Answers

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

mktime takes args hour,minute,second,month,day,year.

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

Date.UTC returns milliseconds whereas mktime returns seconds, so if you still want milliseconds, multiply by 1000.

like image 61
Brad Mace Avatar answered Oct 06 '22 02:10

Brad Mace


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

EDIT: Corrected time zone parameter.

like image 33
Matthew Flaschen Avatar answered Oct 06 '22 02:10

Matthew Flaschen


$ts = gmmktime(0, 0, 0, 2, 22, 1985) * 1000
like image 40
d_burakov Avatar answered Oct 06 '22 01:10

d_burakov