Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

date - PHP - strtotime, specify timezone

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';

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$date = new DateTime($dateStr, new DateTimeZone($timezone));

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...