Convert UTC to “local” time in Go

Keep in mind that the playground has the time set to 2009-11-10 23:00:00 +0000 UTC, so it is working. The proper way is to use time.LoadLocation though, here’s an example: var countryTz = map[string]string{ “Hungary”: “Europe/Budapest”, “Egypt”: “Africa/Cairo”, } func timeIn(name string) time.Time { loc, err := time.LoadLocation(countryTz[name]) if err != nil { panic(err) } … Read more

Java 8 timezone conversions

Try: String isoDateTime = “2014-09-14T17:00:00+00:00”; ZonedDateTime fromIsoDate = ZonedDateTime.parse(isoDateTime); ZoneOffset offset = ZoneOffset.of(“+09:30”); ZonedDateTime acst = fromIsoDate.withZoneSameInstant(offset); System.out.println(“Input: ” + fromIsoDate); System.out.println(“Output: ” + acst.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); Output: Input: 2014-09-14T17:00Z Output: 2014-09-15T02:30:00+09:30 Using OffsetDateTime While it is generally better to use ZonedDateTime as shown above, you can perform the same conversion using OffsetDateTime as follows: String isoDateTime … Read more

Convert UTC offset to timezone or date

It can be done quite simply, by turning the offset into seconds and passing it to timezone_name_from_abbr: <?php $offset=”-7:00″; // Calculate seconds from offset list($hours, $minutes) = explode(‘:’, $offset); $seconds = $hours * 60 * 60 + $minutes * 60; // Get timezone name from seconds $tz = timezone_name_from_abbr(”, $seconds, 1); // Workaround for bug … Read more

javascript toISOString() ignores timezone offset [duplicate]

moment.js is great but sometimes you don’t want to pull a large number of dependencies for simple things. The following works as well: var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds var localISOTime = (new Date(Date.now() – tzoffset)).toISOString().slice(0, -1); console.log(localISOTime) // => ‘2015-01-26T06:40:36.181’ The slice(0, -1) gets rid of the trailing Z which … Read more

Java 8 Date and Time: parse ISO 8601 string without colon in offset [duplicate]

If you want to parse all valid formats of offsets (Z, ±hh:mm, ±hhmm and ±hh), one alternative is to use a java.time.format.DateTimeFormatterBuilder with optional patterns (unfortunatelly, it seems that there’s no single pattern letter to match them all): DateTimeFormatter formatter = new DateTimeFormatterBuilder() // date/time .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) // offset (hh:mm – “+00:00” when it’s zero) .optionalStart().appendOffset(“+HH:MM”, … Read more