我已经看到了一些关于这个但没有明确答案的问题… strtotime()将在将字符串转换为unix时间戳时使用
PHP的默认时区集.
但是,我想将字符串转换为UTC中的unix时间戳.由于没有这样做的参数,怎么办呢?
我想要转换的字符串是:2011-10-27T20:23:39,已经是UTC了.我想将其表示为UTC中的unix时间戳.
谢谢
在进行strtotime调用之前设置系统默认时区:
date_default_timezone_set('UTC');
echo strtotime('2011-10-27T20:23:39')."\n";
// Proof:
print_r(getdate(strtotime('2011-10-27T20:23:39')));
// IMPORTANT: It's possible that you will want to
// restore the prevIoUs system timezone value here.
// It would need to have been saved with
// date_default_timezone_get().
See it in action.