我有一个jQuery脚本,它将日期返回为:
2011年11月9日星期三格林尼治标准时间16:30:00 -0700 (MST)
如何将其转换为unix时间戳?我看过mktime(),但我并没有完全理解它。有什么想法吗?
发布于 2011-11-08 11:59:51
如果您使用的是PHP5.2,请尝试DateTime类,例如
$dt = new DateTime("Wed Nov 09 2011 16:30:00 GMT-0700 (MST)");
$ts = $dt->getTimestamp();否则,请尝试strtotime(),例如
$ts = strtotime("Wed Nov 09 2011 16:30:00 GMT-0700 (MST)");
echo date("r", $ts);对我来说,下面的输出
清华,10 11 10:30:00 +1100
请注意,date()函数支持本地时区
发布于 2011-11-08 12:00:55
我认为jQuery使用的是Date对象;相反,让脚本将Math.floor(theDate.getTime() / 1000)的值发送给您的PHP脚本。这就是您需要的Unix时间戳。
发布于 2011-11-08 12:01:26
那strtotime呢?
$test = strtotime('Wed Nov 09 2011 16:30:00 GMT-0700 (MST)');
echo $test;
output : 1320881400https://stackoverflow.com/questions/8045769
复制相似问题