如何使用javascript创建日期时避免夏令时

如何使用javascript创建日期时避免夏令时

本文介绍了如何使用javascript创建日期时避免夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am testing my application in UK timezone (UTC) Dublin, Edinburgh, Lisbon, London.
The DST (Daylight saving time) in UK starts on Last Sunday of March i.e. 27-Mar-2016.
I am passing unix timestamp to Javascript Date object. It display normal date time but when UK DST is in effect, the time is one hour out




// s - unix timestamp
// ausOffset - Australian Timezone Offset i.e. +10:00(Canberra, Melbourne, Sydney)
// _clientOffset - client machine offset i.e. UK timezone (UTC) Dublin, Edinburgh, Lisbon, London

var _date = new Date(s * 1000);
var _Offset = ausOffset * 60 * 60000; 
var _dateTime = new Date(_date.getTime() + _Offset );
var _clientOffset = _date.getTimezoneOffset() * 60000; 
var _clientTime = new Date(_date.getTime() + _Offset + _clientOffset );
return _clientTime;




How can I avoid DST while creating datetime object in javascript.
Thanks in advance





我尝试过:





What I have tried:

I tried to convert datetime in UTC timezone and added offset in it to get a specific date time.

推荐答案


这篇关于如何使用javascript创建日期时避免夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:18