java - SimpleDateFormat with only milliseconds -
I should use it to parse a date in Java. I am using an existing library which takes a date as string
and a SimpleDateFormat
example to parse it Everything is fine, but I am having problems if the date format is in millisecond only since the time of the era (1/1/1970), i.e. unix time in milliseconds. Using the new SimpleDateFormat ("SS") or New SimpleDateFormat ("SSS")
did not work:
Weird reproduced Code to SimpleDateFormat
Behavior:
Timezone.Set Default (Timezone.Gate Time Zone ("GMT")); // Simply currTimeInMilli = System.currentTimeMillis () for long test; SimpleDateform MSSDF = New SimpleDateform ("SS"); // SimpleDateFormat ("SSS") with the same results SimpleDateFormat secSDF = New SimpleDateFormat ("ss"); System.out.println (msSDF.parse ("+ currTimeInMilli)"; System.out.println (secSDF.parse ("+ (CurrTimeInMilli / 1000))); System.out.println (New SimpleDateform ("EEE MMM DD HH: MM: SS Zz Yay"). Format (Cruelty Inmily));
Produced output:
Mon Dec 15 07:46:20 GMT 1969 & lt; - Should be like two other lines (?)! Mon Apr 28 20:55:19 GMT 2014 - Okay Mon Apr 28 20:55:19 GMT 2014 & lt; OK
Is this normal? How can I enable parsing milliseconds since era
notes:
?- I can not use other libraries such as add-time
- I do not use the
new date (long PNB milli)
to create the date (Legacy LibrarySimpleDateFormat
as an example in the input) - I have learned this but it is not certain that it is directly bound to this issue ...
s
pattern Integer.MAX_VALUE
Much more in comparison The Ekand to be able to handle properly, as bizarre as that usually seem to have volume as a long-term.
If you really want to use an existing API that demands a DateFormat you can always hack it in:
SimpleDateFormat MsSDF = New SimpleDateform ("SSS") {@ Override Public Debt Purse (string source) throws parsextation {Return new date Elong (source)); }};
(It also requires the implementation of a hack of the format (string)
depending on what its legacy API actually does.
Comments
Post a Comment