Reputation:
I understand that it sounds weird but I have datettime 2018-04-04 12:59:575Z
.
Let's assume it is real, not a mistake and I can't find any standard for parsing this.
Is there a way to parse it in Java? What 3 numbers 575
at the end could mean?
edit: There is strong doubt, that it is correct date time in my samples. I'm going to report a bug to creator. Thanks everyone for good advices.
Upvotes: 0
Views: 191
Reputation: 1033
It probably means there's a bug in wherever this string came from. I would investigate there if I had access to that code or report a bug to its owner.
There's no point parsing buggy data and guessing what the numbers mean. Bad data is worse than no data.
Upvotes: 3
Reputation: 86272
What 3 numbers 575 at the end could mean?
My guesses include:
.5
signifying half a second; assuming that the decimal point has been left out from the format).ss
should have been.I can't find any standard for parsing this.
I am pretty convinced that there isn’t any.
Is there a way to parse it in Java?
No, sorry, not as long as we don’t know what the string means.
Upvotes: 2
Reputation: 18245
There could be two possible options for 59
at the end. It could be minutes or seconds. I think, that minutes is more likely, because seconds could be not valuable. 575
is definitely millisecond.
DateTimeFormatter dfMinutes = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SSS");
DateTimeFormatter dfSeconds = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:ss:SSS");
P.S. It could be yyyy-dd-MM
instead of yyyy-MM-dd
. But as I can see, we're in same locale.
Upvotes: 0
Reputation: 5649
You can use joda time api to parse the input String like below:-
String strDate="2018-04-04 12:59:575Z";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:SSSZ");
DateTime dt = formatter.parseDateTime(strDate);
System.out.println(dt); //2018-04-04T08:59:00.575-04:00
575 in your input string is milliseconds.
But you need to find out whats the point of precision till milliseconds if you are not including seconds.
Upvotes: 0