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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With