juxt

niwinz 2016-11-12T01:00:24.000063Z

You also has the option to conver it to long as unix timestamp

niwinz 2016-11-12T01:00:37.000064Z

or miliseconds from the epoch 😄

malcolmsparks 2016-11-12T10:00:49.000065Z

@imre you can convert between java.util.Date and java.time.Instant with .toInstant - doesn't that help?

imre 2016-11-12T10:07:48.000066Z

Thanks guys

imre 2016-11-12T10:08:22.000067Z

These can be good when I want to store instants

imre 2016-11-12T10:09:38.000068Z

My problem is with cases when I want to store data that is not an instant, for example a LocalDate, YearMonth or LocalTime etc.

imre 2016-11-12T10:10:06.000069Z

Or even a ZonedDateTime - Date doesn't have tz info

imre 2016-11-12T10:11:16.000070Z

Usually when I talk about dates, I use LocalDate - that has just the right amount and precision I need, making compatison semantics unambiguous

niwinz 2016-11-12T10:25:32.000071Z

In my opinion, when you are working with dates and persistence, you should work with instants plus a separate field for persist the timezone if it is needed. Later, when you should perform operations or just present that to the user, convert that instant to zoned date...

niwinz 2016-11-12T10:28:46.000072Z

In almost all operations that you are going to do with dates, the correct way is doing them with instant, the timezone information is just a presentation property

niwinz 2016-11-12T10:29:43.000073Z

doing operations with zoned date can cause unexpected situations and strange errors...

imre 2016-11-12T15:51:49.000074Z

thanks for the insight @niwinz - are you aware of any resources where I could find more info about these problems you are referring to?

imre 2016-11-12T15:53:35.000075Z

My experience is almost exactly the opposite

imre 2016-11-12T15:54:43.000076Z

Date seems to be a decent representation of Instants but I found that when talking about dates (without the time part) it has too much info

imre 2016-11-12T15:55:00.000077Z

Or when talking about time-of-the-day

imre 2016-11-12T15:55:46.000078Z

As for zoned datetimes - in case the tz the information was recorded in is not important, Instant is perfect

imre 2016-11-12T15:56:37.000079Z

but when TZ is important I like to keep it bundled otherwise it can get lost or ignored/forgotten to be taken into account

imre 2016-11-12T15:57:26.000080Z

java.time seems to be an improvement over joda time and it seems to have very good semantics for temporal data of varying precision

niwinz 2016-11-12T17:47:17.000083Z

is a good article that explains that

niwinz 2016-11-12T17:49:36.000086Z

this is postgresql related but is pretty interesant to read

niwinz 2016-11-12T17:59:05.000087Z

I was wrong only in one statement: many business logic can require work with ZonedDateTime and many other not. But the persistence and transmission is very recommended to just use Instant or unix epoch or datetime in utc (that in general view is equivalent to instant).