Questions tagged [datetime-parsing]
423 questions
905
votes
29 answers
How do I parse an ISO 8601-formatted date?
I need to parse RFC 3339 strings like "2008-09-03T20:56:35.450686Z" into Python's datetime type.
I have found strptime in the Python standard library, but it is not very convenient.
What is the best way to do this?

Alexander Artemenko
- 21,378
- 8
- 39
- 36
596
votes
11 answers
How do I translate an ISO 8601 datetime string into a Python datetime object?
I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe). One hackish option seems to be to parse the string using time.strptime and passing the first six elements of the tuple into the datetime constructor,…

Andrey Fedorov
- 9,148
- 20
- 67
- 99
260
votes
8 answers
How can I parse a time string containing milliseconds in it with python?
I am able to parse strings containing date/time with time.strptime
>>> import time
>>> time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S')
(2009, 3, 30, 16, 31, 32, 0, 89, -1)
How can I parse a time string that contains milliseconds?
>>>…

ilkinulas
- 3,515
- 3
- 22
- 29
185
votes
7 answers
How to create a .NET DateTime from ISO 8601 format
I've found how to turn a DateTime into an ISO 8601 format, but nothing on how to do the reverse in C#.
I have 2010-08-20T15:00:00Z, and I want to turn it into a DateTime object.
I could separate the parts of the string myself, but that seems like a…

Ripter
- 2,020
- 2
- 14
- 9
103
votes
3 answers
Parse rfc3339 date strings in Python?
I have a datasets where all the dates have the following format:
2012-10-09T19:00:55Z
I'd like to be able to be able to use methods like .weekday on them. How do I convert them to the proper format in Python?

Spearfisher
- 8,445
- 19
- 70
- 124
95
votes
9 answers
Parse DateTime string in JavaScript
Does anyone know how to parse date string in required format dd.mm.yyyy?

Azat
- 2,275
- 1
- 28
- 32
93
votes
5 answers
Parsing time string in Python
I have a date time string that I don't know how to parse it in Python.
The string is like this:
Tue May 08 15:14:45 +0800 2012
I tried
datetime.strptime("Tue May 08 15:14:45 +0800 2012","%a %b %d %H:%M:%S %z %Y")
but Python raises
'z' is a bad…

xiaohan2012
- 9,870
- 23
- 67
- 101
63
votes
4 answers
How to parse a date string into a c++11 std::chrono time_point or similar?
Consider a historic date string of format:
Thu Jan 9 12:35:34 2014
I want to parse such a string into some kind of C++ date representation, then calculate the amount of time that has passed since then.
From the resulting duration I need access to…

Drew Noakes
- 300,895
- 165
- 679
- 742
41
votes
4 answers
Java 8 Date and Time: parse ISO 8601 string without colon in offset
We try to parse the following ISO 8601 DateTime String with timezone offset:
final String input = "2022-03-17T23:00:00.000+0000";
OffsetDateTime.parse(input);
LocalDateTime.parse(input, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
Both approaches fail…

Ursin Brunner
- 2,310
- 1
- 24
- 24
39
votes
5 answers
Natural/Relative days in Python
I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc.
Django 1.0 has a "humanize" method in django.contrib. I'm…

JJ.
- 4,974
- 5
- 39
- 48
39
votes
4 answers
JSR-310 - parsing seconds fraction with variable length
Is there a way how to create JSR-310 formatter that is able to parse both following date/times with variable length of seconds fraction?
2015-05-07 13:20:22.276052
or
2015-05-07 13:20:22.276
Example code:
DateTimeFormatter formatter
= new…

JiriS
- 6,870
- 5
- 31
- 40
29
votes
2 answers
Java 8 DateTimeFormatter parsing for optional fractional seconds of varying significance
My MCVE (as a TestNG unit test):
public class MyDateTimeFormatterTest {
private static final String BASE_PATTERN = "yyyy/MM/dd HH:mm:ss";
private static final DateTimeFormatter FORMATTER =
…

h.j.k.
- 1,357
- 2
- 20
- 30
25
votes
6 answers
How to parse date-time with two or three milliseconds digits in java?
Here is my method to parse String into LocalDateTime.
public static String formatDate(final String date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS");
LocalDateTime formatDateTime =…

brain storm
- 30,124
- 69
- 225
- 393
22
votes
6 answers
Parse 'Date & Time' string in Javascript which are of custom format
I have to parse a date and time string of format "2015-01-16 22:15:00". I want to parse this into JavaScript Date Object. Any help on this?
I tried some jquery plugins, moment.js, date.js, xdate.js. Still no luck.

yuva
- 3,108
- 4
- 20
- 35
22
votes
5 answers
SimpleDateFormat producing wrong date time when parsing "YYYY-MM-dd HH:mm"
I am trying to parse a String (YYYY-MM-dd HH:mm) to Date, however getting wrong date than expected.
CODE:
Date newDate = null;
String dateTime = "2013-03-18 08:30";
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm",…

Sas
- 2,473
- 6
- 30
- 47