Questions tagged [date-parsing]

Date-parsing refers to programming logic which reads one or more parameters, attempts to match it to a supported or specified date format, then returns the resulting Date if successful.

References

431 questions
766
votes
35 answers

Converting a string to a date in JavaScript

How can I convert a string to a date in JavaScript? var st = "date in some format" var dt = new date(); var dt_st= //st in date format same as dt
jslearner
  • 18,191
  • 17
  • 35
  • 35
309
votes
7 answers

Format date with Moment.js

I have a string in this format: var testDate = "Fri Apr 12 2013 19:08:55 GMT-0500 (CDT)" I would like to use Moment.js get it in this format mm/dd/yyyy : 04/12/2013 for display. I tried to do it using this…
Warz
  • 6,588
  • 14
  • 64
  • 114
55
votes
2 answers

Parse date in MySQL

How to convert the following into date for insertion/update into a TIMESTAMP or DATE field in MySQL? '15-Dec-09' DATE_FORMAT() is used to format date, but not the other way around.
user157195
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

Parse Date String to Some Java Object

I am working in a project that reads files and processes data. There I got to work with dates for example: 2012-01-10 23:13:26 January 13, 2012 I found the package Joda, kinda interesting package but don't know if it is the easiest around. I was…
Ziyan Junaideen
  • 2,914
  • 5
  • 38
  • 67
31
votes
7 answers

How do I parse RFC 3339 datetimes with Java?

I'm trying to parse the date returned as a value from the HTML5 datetime input field. Try it in Opera to see an example. The date returned looks like this: 2011-05-03T11:58:01Z. I'd like to parse that into a Java Date or Calendar Object. Ideally a…
Adam
  • 39,529
  • 15
  • 101
  • 139
28
votes
2 answers

Parse a date in rails

I have a date (Which is actually parsed from a PDF) and it could be any of the following format: MM/DD/YYYY MM/DD/YY M/D/YY October 15, 2007 Oct 15, 2007 Is there any gem or function available in rails or ruby to parse my date? Or I need to parse…
Sachin Prasad
  • 5,038
  • 12
  • 49
  • 91
27
votes
5 answers

java.time.format.DateTimeParseException: Text could not be parsed at index 3

I am using Java 8 to parse the the date and find difference between two dates. Here is my snippet: String date1 ="01-JAN-2017"; String date2 = "02-FEB-2017"; DateTimeFormatter df = DateTimeFormatter .ofPattern("DD-MMM-YYYY", en); LocalDate d1 =…
Uma
  • 273
  • 1
  • 3
  • 5
26
votes
1 answer

c++ Why is my date parsing not threadsafe?

boost::posix_time::ptime parseDate(const std::string& format, const std::string& localDate) { std::istringstream is(localDate); is.imbue(std::locale(is.getloc(), new boost::local_time::local_time_input_facet(format.c_str()))); …
tauran
  • 7,568
  • 6
  • 36
  • 46
24
votes
2 answers

Ruby parse date string

I need to parse a date string mentioned below to std date format. Is there a built in function in ruby that would parse something like, December 09, 2011 to 2011-12-09
user1810502
  • 461
  • 2
  • 6
  • 17
23
votes
4 answers

Why SimpleDateFormat("MM/dd/yyyy") parses date to 10/20/20128?

I have this code: DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); dateFormat.setLenient(false); Date date = dateFormat.parse("10/20/20128"); and I would expect the dateFormat.parse call to throw ParseException since the year I'm…
goe
  • 333
  • 1
  • 3
  • 13
21
votes
5 answers

How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)

i'm managing a date that comes from an Alfresco Properties and is in the specified (Tue Jul 13 00:00:00 CEST 2010) and i need to convert it to a Java date...i've looked around and found millions of posts for various string to date conversion form…
Nicola Peluchetti
  • 72,169
  • 29
  • 129
  • 186
20
votes
4 answers

Parsing a date’s ordinal indicator ( st, nd, rd, th ) in a date-time string

I checked the SimpleDateFormat javadoc, but I am not able to find a way to parse the ordinal indicator in a date format like this: Feb 13th 2015 9:00AM I tried "MMM dd yyyy hh:mma", but the days have to be in number for it to be correct? Is it…
hao
  • 545
  • 2
  • 6
  • 17
19
votes
6 answers

convert String "yyyy-MM-dd" to LocalDateTime

Is there any way to convert a date String to LocalDateTime where the format "yyyy-MM-dd" ? If I try this: DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime ldt = LocalDateTime.parse(string, DATEFORMATTER); I…
LakiGeri
  • 1,587
  • 3
  • 22
  • 49
18
votes
4 answers

JDK8: unable to parse LocalTime

I managed to parse a String to a LocalDate object: DateTimeFormatter f1=DateTimeFormatter.ofPattern("dd MM yyyy"); LocalDate d=LocalDate.parse("26 08 1984",f1); System.out.println(d); //prints "1984-08-26" But I cannot do the same with LocalTime.…
Luigi Cortese
  • 9,451
  • 5
  • 33
  • 47
1
2 3
28 29