dst

Working with timezones and daylight savings time in Javascript

北战南征 提交于 2019-11-28 07:25:55
My single-page javascript app retrieves data in JSON format via REST calls. Dates come formatted using the UTC timezone in standard ISO8601 format, such as 2011-02-04T19:31:09Z . When signing up for the service, users select their timezone from a drop down list. This timezone could be different than the user's browser's timezone. The javascript app knows what the user's selected timezone is at all times. I know how to convert the UTC string into a date. I understand that Javascript only represents dates in the local timezone. But I'm having troubles figuring out how to display a date formatted

Eliminating Javascript daylight saving time gap, a cross-browser solution

↘锁芯ラ 提交于 2019-11-28 05:26:18
问题 After lots of hassle I finally found the actual problem. It's the gap induced by daylight saving and the fact that different browsers act differently if timezone is set on UTC+3:30 (I'm not sure of other timezones). Here's a snippet to generate the problem (the problem is reproducible if your system's TZ is set to UTC+3:30): function zeroPad(n) { n = n + ''; return n.length >= 2 ? n : new Array(2 - n.length + 1).join('0') + n; } document.write("<table border='1' cellpadding='3'><tr><td>Input

Accounting for DST in Postgres, when selecting scheduled items

混江龙づ霸主 提交于 2019-11-28 05:06:45
I have a Postgres table of clock alarms (not really, but this is analogous, and easier to explain). Alarms are set by users with a 1 hour resolution, and users can be from many different timezones. The alarms are repeating daily. I want to reliably fetch the alarms that are supposed to go off at a particular hour of the day, and I am having problems with daylight saving time . How do I do this in the best way? Example Alfred and Lotta both live in Stockholm (+1 hour from UTC, but +2h when it's DST). Sharon lives in Singapore (+8 hours from UTC, no DST) During winter, Alfred sets an alarm for 4

Javascript Date objects and Daylight Savings Time

此生再无相见时 提交于 2019-11-28 04:36:15
问题 I'm seeing some behavior I don't understand with Javascript date objects and DST transitions. If I execute the following in Chrome's javascript console var date = new Date(1268535600000); //2010-03-14T03:00:00.000Z (21:00 03-13 America/Chicago) for(var i = 1; i <= 12; i++) { var time = date.getHours(); console.log(time) console.log(date) date.setHours(date.getHours() + 1); } the output is: 21 Sat Mar 13 2010 21:00:00 GMT-0600 (Central Standard Time) 22 Sat Mar 13 2010 22:00:00 GMT-0600

C# event to detect Daylight Saving or even manual time change

人盡茶涼 提交于 2019-11-28 02:08:36
I run an application as a service on a server and then I have multiple clients connect to that service. I display the exact server time on each of the client Window form application and because of that I need a mechanism to detect any time change on the server so that I can send it to the client to display. Looking over the MSDN I found SystemEvents.TimeChanged , I thought I'm in luck because when testing with the code below with Visual Studio everything works great: SystemEvents.TimeChanged += new EventHandler(SystemEvents_TimeChanged); static void SystemEvents_TimeChanged(object sender,

org.joda.time | Day Light Saving time (DST) and local time zone offset

徘徊边缘 提交于 2019-11-28 01:35:11
问题 just to verify this: I have this lame and brain dead method to calculate the time zone offset for my current location. I wonder if I need to adjust it when Day Light Saving time comes into question (currently we have Winter Time at my location, CET time zone, so it's hard to verify). // The local time zone's offset private int getLocalOffset() { DateTimeZone defaultZone = DateTimeZone.getDefault(); return defaultZone.getOffset(null) / 1000 / 60 / 60; } Thanks for any hint. 回答1: Normally, Joda

java.util.Date Calculate difference in days

旧街凉风 提交于 2019-11-28 00:12:41
I tried to calculate the difference between two dates and I noticed one thing. When calculating only the days, the start of daylight saving time is included in the interval, so the result will be shorter with 1 day. To obtain accurate results, the value of hours also must be considered. For example: SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); Date dfrom = format.parse("03-29-2015"); Date dto = format.parse("03-30-2015"); long diff = dto.getTime() - dfrom.getTime(); System.out.println(diff); System.out.println("Days: "+diff / (24 * 60 * 60 * 1000)); System.out.println("Hours:

Getting Daylight Savings Time Start and End in NodaTime

岁酱吖の 提交于 2019-11-27 21:46:33
问题 How can I get the starting and ending dates for Daylight Savings Time using Noda Time? The function below accomplishes this task but it is horribly unwieldy and is begging for a simpler solution. /// <summary> /// Gets the start and end of daylight savings time in a given time zone /// </summary> /// <param name="tz">The time zone in question</param> /// <returns>A tuple indicating the start and end of DST</returns> /// <remarks>Assumes this zone has daylight savings time</remarks> private

c# daylight savings duplicate hour convert to UTC

不想你离开。 提交于 2019-11-27 20:56:48
问题 I am using TimeZoneInfo to convert between client side wallclock 'Eastern Time' and UTC. My problem is with the 'duplicate' hour that occurs during autumn DST change. During conversion from UTC to Eastern: 2010-11-07 06:00 UTC --> gives 2010-11-07T 01 :00:00-03:30 2010-11-07 07:00 UTC --> gives 2010-11-07T 01 :00:00-03:30 How can I know which is first hour and which is second? DateTime.IsDaylightSavingTime() returns false for both hours, but shouldn't it return true for the first hour?

Convert a unixtime to a datetime object and back again (pair of time conversion functions that are inverses)

无人久伴 提交于 2019-11-27 20:52:55
问题 I'm trying to write a pair of functions, dt and ut , that convert back and forth between normal unix time (seconds since 1970-01-01 00:00:00 UTC) and a Python datetime object. If dt and ut were proper inverses then this code would print the same timestamp twice: import time, datetime # Convert a unix time u to a datetime object d, and vice versa def dt(u): return datetime.datetime.fromtimestamp(u) def ut(d): return time.mktime(d.timetuple()) u = 1004260000 print u, "-->", ut(dt(u)) Alas, the