views:

38

answers:

2

How can I say this Javascript in PHP:

var ts=Date.UTC(1985,1,22);

Thanks in advance.

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

EDIT: Corrected time zone parameter.

Matthew Flaschen
Using this method you could then call `$ts->getTimestamp()` to get the timestamp (again in seconds since the epoch)
bemace
@bemace, yes, I found that just before I saw your comment.
Matthew Flaschen
Also, mktime uses GMT, whereas this method does provide actual UTC support in the rare case that the difference actually matters to you.
bemace
+3  A: 

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 still want milliseconds, multiply by 1000.

bemace