Java Date to milliseconds

amazon-web-services, date, java, time

Solution

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.

Problem

I'm storing messages from an amazon cloud and ordering them by their timestamp in a sorted map. I am parsing the timestamp from the cloud with the following code: ``` Date timestamp = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'", Locale.ENGLISH).parse(time); ``` and then I am storing in them in a sorted map with the key being the date. The issue is that the date only comes down to seconds precision. I can have several messages sent in 1 second, so I need them to be ordered with millisecond precision. Is there a data structure that allows this?

Original source