Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将JavaScript日期转换为不同的时区_Javascript_Date_Datetime_Timezone_Timestamp - Fatal编程技术网

如何将JavaScript日期转换为不同的时区

如何将JavaScript日期转换为不同的时区,javascript,date,datetime,timezone,timestamp,Javascript,Date,Datetime,Timezone,Timestamp,如果我运行var myDate=new Date('29-06-2016 10:00'),myDate将只包含一件事:一个数字。从1970年1月1日00:00:00 GMT到2016年6月29日10:00:00 XXX的毫秒数 XXX是操作系统的时区。在我的例子中,英国夏令时(因为这是一个夏天,冬天应该是格林威治标准时间) 现在。。。如果我想要1970年1月1日的毫秒数。。。2016年6月29日10:00:00 GMT-7 当英国夏令时时区是29-06-2016 10:00:00时,我只找到方法

如果我运行
var myDate=new Date('29-06-2016 10:00')
myDate
将只包含一件事:一个数字。从1970年1月1日00:00:00 GMT到2016年6月29日10:00:00 XXX的毫秒数

XXX是操作系统的时区。在我的例子中,英国夏令时(因为这是一个夏天,冬天应该是格林威治标准时间)

现在。。。如果我想要1970年1月1日的毫秒数。。。2016年6月29日10:00:00 GMT-7

当英国夏令时时区是29-06-2016 10:00:00时,我只找到方法告诉我GMT-7时区的时间,但这不是我想要的


此外,更改环境变量以使时区为GMT-7也不是一个选项。

我想您需要以下格式的日期字符串

"2016-06-29T10:00:00-07:00"
这使您可以设置时区相对GMT(时区不是100%确定的,但它是客户端的,因此取决于它们的区域设置)

我有一个类似的例子,JS正在更改日期对象上的时间,我找到的唯一方法就是设置日期并设置它

奖金信息,使用以下字符串格式从.NET日期时间获取

"yyyy-MM-ddTHH:mm:sszzz"

我想您需要以下格式的日期字符串

"2016-06-29T10:00:00-07:00"
这使您可以设置时区相对GMT(时区不是100%确定的,但它是客户端的,因此取决于它们的区域设置)

我有一个类似的例子,JS正在更改日期对象上的时间,我找到的唯一方法就是设置日期并设置它

奖金信息,使用以下字符串格式从.NET日期时间获取

"yyyy-MM-ddTHH:mm:sszzz"

我想我找到了一种方法,按照建议使用:

// This code is running in a Node.js server configured to use UTC

// Incorrect date, as it is interpret as UTC.
// However, we do this to get the utcOffset
var auxDate = moment.tz(new Date('2016-6-23 10:15:0'), 'US/Mountain');

// Get the milliseconds since 1970 of the date as if it were interpreted 
// as GMT-7 or GMT-6 (depends on the date because of Daylight Saving Time)
var milliseconds = auxDate.valueOf() - auxDate.utcOffset() * 60000;

我想我找到了一种方法,按照建议使用:

// This code is running in a Node.js server configured to use UTC

// Incorrect date, as it is interpret as UTC.
// However, we do this to get the utcOffset
var auxDate = moment.tz(new Date('2016-6-23 10:15:0'), 'US/Mountain');

// Get the milliseconds since 1970 of the date as if it were interpreted 
// as GMT-7 or GMT-6 (depends on the date because of Daylight Saving Time)
var milliseconds = auxDate.valueOf() - auxDate.utcOffset() * 60000;

也许这一刻能帮上忙。。但不确定。也许这一刻能帮上忙。。但不确定。是的,
Date.parse(“2016-06-29T10:00:00-07:00”)
在Chrome、Firefox、IE和Edge中都能工作,所以看起来是一个安全的赌注。在我的情况下不起作用。我使用的服务器是(而且必须是)UTC。。。所以我需要知道什么时候是夏季和冬季,并相应地更改字符串日期。是的,
Date.parse(“2016-06-29T10:00:00-07:00”)
在Chrome、Firefox、IE和Edge中工作,所以看起来是一个安全的赌注。在我的情况下不起作用。我使用的服务器是(而且必须是)UTC。。。因此,我需要知道什么时候是夏季和冬季,并因此更改字符串日期。