timezone-offset
How can I extract the value of my current local time offset?
You can use the Zone() method on the time type: package main import ( “fmt” “time” ) func main() { t := time.Now() zone, offset := t.Zone() fmt.Println(zone, offset) } Zone computes the time zone in effect at time t, returning the abbreviated name of the zone (such as “CET”) and its offset in seconds … Read more
JavaScript check if timezone name valid or not
In environments that fully support IANA time zone identifiers in ECMA-402 (ECMAScript Internationalization API), you can try using a time zone in a DateTimeFormat (or in the options of to toLocaleString) and it will throw an exception if it is not a valid time zone. You can use this to test for validity, but only … Read more
Django default=timezone.now + delta
default takes a callable, so you just need to write a function to do what you want and then provide that as the argument: def one_day_hence(): return timezone.now() + timezone.timedelta(days=1) class MyModel(models.Model): … key_expires = models.DateTimeField(default=one_day_hence) (As discussed here, resist the temptation to make this a lambda.)
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 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
Identifying time zones in ISO 8601
Update: There’s now a draft IETF proposal to extend RFC3339 with the time zone identifier in square brackets, among other things: https://datatracker.ietf.org/doc/draft-ietf-sedate-datetime-extended/ Original Answer: I understand these are not supported by ISO 8601, correct? Correct. ISO-8601 does not concern itself with time zone identifiers. IANA/Olson TZ names are not a “standard”. They are just the … Read more
Free Rest API to retrieve current datetime as string (timezone irrelevant) [closed]
TimezoneDb provides a free API: http://timezonedb.com/api GenoNames also has a RESTful API available to get the current time for a given location: http://www.geonames.org/export/ws-overview.html. You can use Greenwich, UK if you’d like GMT.
Python pytz timezone function returns a timezone that is off by 9 minutes
Answer based on the answer by Carl Meyer in Google Groups Answer The reason for this difference, is that this is NOT the right way of converting a timezone agnostic datetime object to a timezone aware object. The explanation being: “A pytz timezone class does not represent a single offset from UTC, it represents a … Read more
Why does JavaScript Date.getTimezoneOffset() consider “-05:00” as a positive offset?
Because that’s how it’s defined. Quoting the doc (MDN): The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead.