Questions tagged [datetime-parsing]

360 questions
735
votes
27 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
  • 16,382
  • 8
  • 36
  • 36
474
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
  • 7,836
  • 20
  • 63
  • 95
224
votes
7 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,155
  • 3
  • 20
  • 25
145
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
  • 1,620
  • 2
  • 12
  • 9
139
votes
9 answers

Parse date string and change format

I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?
Nimmy
  • 4,001
  • 7
  • 28
  • 32
102
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
  • 7,303
  • 17
  • 59
  • 115
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,215
  • 1
  • 27
  • 31
70
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
  • 8,118
  • 18
  • 59
  • 98
48
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
  • 266,361
  • 143
  • 616
  • 705
37
votes
6 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…
jamtoday
  • 4,734
  • 5
  • 37
  • 48
34
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
  • 1,880
  • 1
  • 20
  • 22
24
votes
1 answer

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,187
  • 1
  • 17
  • 26
19
votes
6 answers

Is there a way to find the first string that matches a DateTime format string?

Given a date time format string, is there a standard way to find the first matching substring that matches that format? for example, given... d-MMM-yy H:mm:ss and some text... "blah 1 2 3 7-Jul-13 6:15:00 4 5 6 blah" I'd expect it to return…
Keith Nicholas
  • 41,161
  • 15
  • 82
  • 145
19
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,313
  • 5
  • 27
  • 46
18
votes
5 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
  • 2,472
  • 4
  • 15
  • 29
1
2 3
23 24