Convert timestamps with offset to datetime obj using strptime

The Python 2 strptime() function indeed does not support the %z format for timezones (because the underlying time.strptime() function doesn’t support it). You have two options: Ignore the timezone when parsing with strptime: time_obj = datetime.datetime.strptime(time_str[:19], ‘%Y-%m-%dT%H:%M:%S’) use the dateutil module, it’s parse function does deal with timezones: from dateutil.parser import parse time_obj = parse(time_str) … Read more

Java: Date from unix timestamp

For 1280512800, multiply by 1000, since java is expecting milliseconds: java.util.Date time=new java.util.Date((long)timeStamp*1000); If you already had milliseconds, then just new java.util.Date((long)timeStamp); From the documentation: Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as “the epoch”, namely January 1, 1970, 00:00:00 GMT.

How to parse/format dates with LocalDateTime? (Java 8)

Parsing date and time To create a LocalDateTime object from a string you can use the static LocalDateTime.parse() method. It takes a string and a DateTimeFormatter as parameter. The DateTimeFormatter is used to specify the date/time pattern. String str = “1986-04-08 12:30”; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm”); LocalDateTime dateTime = LocalDateTime.parse(str, formatter); Formatting date and … Read more