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

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

tech