How can I parse a time string containing milliseconds in it with python?

Python 2.6 added a new strftime/strptime macro %f. The docs are a bit misleading as they only mention microseconds, but %f actually parses any decimal fraction of seconds with up to 6 digits, meaning it also works for milliseconds or even centiseconds or deciseconds. time.strptime(’30/03/09 16:31:32.123′, ‘%d/%m/%y %H:%M:%S.%f’) However, time.struct_time doesn’t actually store milliseconds/microseconds. You’re … Read more

Parsing ISO-8601 DateTime with offset with colon in Java

The “strange” format in question is ISO-8601 – its very widely used. You can use SimpleDateFormat to reformat it in most way you please: SimpleDateFormat inFormat = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssZ”); DateTime dtIn = inFormat.parse(dateString}); //where dateString is a date in ISO-8601 format SimpleDateFormat outFormat = new SimpleDateFormat(“dd.MM.yyyy HH:mm”); String dtOut = outFormat.format(dtIn); //parse it into a … Read more

java.text.ParseException: Unparseable date: java.text.DateFormat.parse(DateFormat.java:579)

Never use SimpleDateFormat or DateTimeFormatter without a Locale Since the given date-time is in English, you should use Locale.ENGLISH with your date-time parser; otherwise the parsing will fail in a system (computer, phone etc.) which is using a non-English type of locale. Also, note that the date-time API of java.util and their formatting API, SimpleDateFormat … Read more

How do I translate an ISO 8601 datetime string into a Python datetime object? [duplicate]

I prefer using the dateutil library for timezone handling and generally solid date parsing. If you were to get an ISO 8601 string like: 2010-05-08T23:41:54.000Z you’d have a fun time parsing that with strptime, especially if you didn’t know up front whether or not the timezone was included. pyiso8601 has a couple of issues (check … Read more