Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - strtotime, specify timezone

Tags:

date

timezone

php

I have a date string, say '2008-09-11'. I want to get a timestamp out of this, but I need to specify a timezone dynamically (rather then PHP default).

So to recap, I have two strings:

$dateStr = '2008-09-11'; $timezone = 'Americas/New_York'; 

How do I get the timestamp for this?

EDIT: The time of day will be the midnight of that day.... $dateStr = '2008-09-11 00:00:00';

like image 735
Andy Hin Avatar asked Aug 25 '10 18:08

Andy Hin


1 Answers

$date = new DateTime($dateStr, new DateTimeZone($timezone)); 

$timestamp = $date->format('U');

like image 72
salathe Avatar answered Sep 21 '22 13:09

salathe