简体   繁体   English

javascript new Date()设置为GMT -4

[英]javascript new Date() set to GMT -4

my server is on GMT -4 and all the records which go into the database are GMT -4 using 我的服务器在GMT -4上,进入数据库的所有记录都是GMT -4

<?php date("Y-m-d H:i:s");?>

so if the time was 15:00:00 GMT +1 (my current timezone) 因此,如果时间是15:00:00 GMT +1(我当前的时区)
the time added to the database would be 10:00:00. 添加到数据库的时间将是10:00:00。

however when I use javascript new Date(); 但是,当我使用javascript new Date(); it gives it as 它给它作为

Thu Aug 29 2013 22:17:00 GMT+0100 (GMT Summer Time)

i have this function to convert the js date to php 我有此功能将js日期转换为php

$jsDate = $_REQUEST["date"];
$jsDateTS = strtotime($jsDate);
if ($jsDateTS !== false) 
{
$jsDateTS = date('Y-m-d H:i:s', $jsDateTS );
echo $jsDateTS."<br>";

but it writes 2013-08-29 22:17:00 and not 2013-08-28 17:17:00 which is what I need. 但它写的是2013-08-29 22:17:00而不是2013-08-28 17:17:00这是我需要的。

how do I convert my javascript new Date to GMT -4? 如何将我的JavaScript新日期转换为GMT -4? is it possible or not? 有没有可能?

thanks, and sorry if I am unclear in any way. 谢谢,对不起,如果我不清楚。

my solution was the following 我的解决方案是以下

client side 客户端

var date = new Date();
date = date.toUTCString();

server side 服务器端

$date = date('Ymd H:i:s', strtotime($_REQUEST["date"]) );

thanks for all others who answered 感谢所有其他回答

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

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