如何将PHP(servertime) 中的$ datetime转换为使用JS的用户本地时区?
<span class="datetime"><?php echo $datetime; ?></span>
这可能吗?
如何将PHP(servertime) 中的$ datetime转换为使用JS的用户本地时区?
<span class="datetime"><?php echo $datetime; ?></span>
这可能吗?
您可以使用momentjs或moment timezone
function toTimeZone(time, zone) {
var format = 'YYYY/MM/DD HH:mm:ss ZZ';
return moment(time, format).tz(zone).format(format);
}
这个怎么样。设置你的初始值是UNIX时间戳:
<span class="datetime"><?php echo strtotime($datetime); ?></span>
然后使用JQuery与本地时区的日期时间,以取代时间戳:
$(function() {
$(".datetime").each(function(idx) {
var converted = new Date(parseInt($(this).text()) * 1000);
$(this).text(converted.toString("ddd MMM d yyyy H:mm:ss"));
});
});
什么是$ datetime.Answer的价值取决于它的价值。 –
$ datetime是一个MySQL值,例如'2012-06-08 18:00:00' – McBabba
然而答案仍然取决于你的服务器时区。如果你将其转换为unix时代,它会更好。 –