If (! standardDateTime.The province of Manitoba is the only province or territory in Canada that observes Central Time in all areas. = ZonedDateTime.ofLocal(dateTime, zone, dstOffset) = ZonedDateTime.ofLocal(dateTime, zone, standardOffset) ZoneOffset dstOffset = ZoneOffset.ofHours(-5) We can at least detect the ambiguous times: ZoneOffset standardOffset = ZoneOffset.ofHours(-6)
#Cst time zone now code#
Other options include just taking DST time every time - this is what the above code will do - or taking an average and living with the error thus introduced. You may want to think about whether something similar will be possible for you. In this case we might have solved it using the information that times were in summer time until the leap backward by an hour, from there they were in standard time. Since we assumed time would always move forward, we failed at the transition to standard time, and one hour of the log file was lost. I once had to parse a log file containing date-times without indication of standard time and summer time (DST). If America/Mexico_City time zone is not appropriate for you, pick a better one, for example America/Rainy_River or America/Chicago. Since your month abbreviation is in all uppercase, I needed to tell the formatter to parse case insensitively. You can see that it picked an offset of -06:00, which means that the time is in standard time (CDT is -05:00). ZonedDateTime firstShot = ZonedDateTime.of(dateTime, zone) LocalDateTime dateTime = LocalDateTime.parse(storedTime, storedFormatter) ZoneId zone = ZoneId.of("America/Mexico_City") appendPattern("d-MMM-uu hh.mm.ss.SSSSSSSSS a") What we can do with it: DateTimeFormatter storedFormatter = new DateTimeFormatterBuilder() I am taking your word for your date-time string format.
#Cst time zone now upgrade#
It has been backported to Java 6 and 7 in the ThreeTen Backport, so it’s a matter of getting this and adding it to your project (just until one day you upgrade to Java 8 or later). You can still use java.time, the modern Java date and time API also known as JSR-310. This answer will take you as far into the future as possible without taking you away from Java 7. Only times from the two hours around the transition from DST to standard time are ambiguous, and as said in the comments, there is no way to know from the time stamp which is the right way to resolve this ambiguity. More on this ambiguity later.įor 99.977 % of all times it is fairly easy to know whether they are standard time or daylight saving time. I am assuming by CST and CDT you mean North American Central Standard Time and Central Daylight Time such as observed in Rainy River, Chicago and Mexico (the city) among other places.