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

494 questions
931
votes
35 answers

Parsing a string to a date in JavaScript

How can I convert a string to a Date object in JavaScript? var st = "date in some format" var dt = new Date(); var dt_st = // st in Date format, same as dt.
jslearner
  • 21,331
  • 18
  • 37
  • 35
367
votes
9 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
  • 7,386
  • 14
  • 68
  • 120
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
59
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
50
votes
6 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
  • 503
  • 1
  • 4
  • 5
38
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
  • 3,270
  • 7
  • 46
  • 71
38
votes
9 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
  • 43,763
  • 16
  • 104
  • 144
33
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,365
  • 12
  • 54
  • 101
32
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
  • 2,046
  • 6
  • 30
  • 56
28
votes
2 answers

Ruby parse date string

I need to parse a date string mentioned below into a Date object. Is there a built in function in Ruby that would parse something like the string "December 09, 2011" to a Date of 2011-12-09?
user1810502
  • 531
  • 2
  • 7
  • 19
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,986
  • 6
  • 41
  • 48
24
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
  • 76,206
  • 31
  • 145
  • 192
24
votes
5 answers

String-Date conversion with nanoseconds

I've been struggling for a while with this piece of code for an Android app and I can't get the hang of it. I've read and tried every solution I found on stackoverflow and other places, but still no luck. What I want to do is have a function to…
23
votes
5 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
  • 343
  • 1
  • 4
  • 13
22
votes
4 answers

Java: Unable to obtain LocalDate from TemporalAccessor

I am trying to change the format of a String date from EEEE MMMM d to MM/d/yyyy by, first, converting it into a LocalDate and then applying a formatter of a different pattern to the LocalDate before parsing it into String again. Here's my…
user7049000
1
2 3
32 33