Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with parsing Date string

I'm trying to parse the following string to a Date object:

2013-12-26T01:00:56.664Z

Using this SimpleDateFormat:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

But I'm getting a:

 java.text.ParseException: Unparseable date: "2013-12-26T01:00:56.664Z" (at offset 19)

What am I doing wrong, How I should handle the T and the Z letters in the date?

like image 571
Emil Adz Avatar asked Nov 26 '13 10:11

Emil Adz


People also ask

How to parse date string in js?

The parse() method takes a date string (such as "2011-10-10T14:48:00" ) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. This function is useful for setting date values based on string values, for example in conjunction with the setTime() method and the Date object.

What can I use instead of date parse?

If the DATEPARSE function is not available for the data that you're working with, or the field you are trying to convert is a number data type, you can use the DATE function instead. The DATE function converts a number, string or date expression to a date type.

What does parsing date mean?

Parsing means converting one type of data to other types. For example, If we want to convert a string date to a date object, then it is said to parsing. Date Parsing purpose is whenever we get data from the third party, we don't know that the given date in their documents is date object or date String object.

How do you parse a date in python?

Python has a built-in method to parse dates, strptime . This example takes the string “2020–01–01 14:00” and parses it to a datetime object. The documentation for strptime provides a great overview of all format-string options.


1 Answers

The real isssue with the date is not T & Z but the milliseconds.

"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" This must be the format that is to be used becaue there are milli seconds as well in the input date.

like image 85
Buddha Avatar answered Sep 22 '22 02:09

Buddha