从具有特定时区和特定$now值的相对日期/时间字符串中获取时间戳


Getting timestamp from relative date/time string with specific timezone AND specific $now value

我知道有两种方法可以从PHP中的相对日期/时间字符串中获取时间戳:

strtotime:允许用户指定自己的$now值

日期时间对象:允许用户指定自己的$timezone值

有没有办法从日期/时间字符串中获取时间戳,允许同时指定时区和$now值?似乎唯一的方法是使用 strtotime,同时暂时覆盖整个 php 应用程序的默认时区,然后立即将其设置回来。这似乎是一个黑客解决方案,如果有更清洁的方法,那就太好了。

编辑:似乎对我想要做的事情有一些误解。下面是一个更具体的例子:

"我想在美国/Los_Angeles时区内找到与字符串'下周二下午 3:00'相对应的时间戳,并为$now指定一个任意值,例如 2014 年 3 月 14 日上午 8:05。"

我准备了一个例子。这可能是你想要的:

<?php
// Including the timezone int the time strings (thanks @Mike B!!!) 
// will make it very easy.  just strtotime() is required
// create a timestamp for March 14th PDT
$now = strtotime('14 March 2014 8:05am America/Los_Angeles');
// get the requested timestamp.
$nexTuesday = strtotime('next tuesday 3:00 pm America/Los_Angeles', $now);