Java Date to milliseconds

Well as long as your source has a higher resolution than 1 second. Looks like that from the pattern, but you haven't shown us any input example.

Date is just a wrapper around a long milliseconds since 1970-01-01. So you have that already. Date.getTime() will return that, with millisecond precision.

Why would you think that Date only has one second precision? Date.compareTo(Date anotherDate) compares on a millisecond level. So your SortedMap should work fine unless you are doing something strange.


I am not sure if you have done this, but you can create your own comparator and use that.

As a side note, depending on your applications setup you may want to be careful with how you use SimpleDateFormat, there are some issues with it.