简体   繁体   English

如何使用strtotime()解析不同时区的字符串

[英]How can I parse a string using strtotime() for different timezones

I have an input string that will look something like 我有一个输入字符串,看起来像

"Monday 2:00 pm" and I need to get a timestamp representation of this, but I cant figure out how to introduce different timezones. “星期一2:00 pm”,我需要对此进行时间戳记表示,但是我无法弄清楚如何引入不同的时区。

For example right now I just simply do 例如,现在我只是简单地做

 $name = "Monday";
 $time_string = "2:00 pm";

 $time_stamp = strtotime("$name $time_string");

which will get me a timestamp but say someone in 'America/New_York' inputs this v someone in 'America/Los_Angeles' the timestamps should be different correct? 这会给我一个时间戳,但是说“ America / New_York”中的某人输入了此v对“ America / Los_Angeles”中的某人而言,时间戳应该不同吗?

I believe you can set the default timezone before you call strtotime: 我相信您可以在调用strtotime之前设置默认时区:

date_default_timezone_set('America/New_York');

But the UNIX epoch is always in UTC, so I'm not sure this makes any difference to the timestamp: 但是UNIX时代始终是UTC,所以我不确定这对时间戳有什么影响:

// New York
date_default_timezone_set('America/New_York');
echo time(); // 1322309733

// London
date_default_timezone_set('Europe/London');
echo time(); // 1322309733

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM