I'm parsing dates from a Dataset[Transaction] objects in order to collect a set of dictinct values:
val distinctTransactionDates: Set[Date] = transactions.map(t => t.transaction_date).distinct().collect().toSet
But the dates are parsed incorrectly, for example if a transaction's Date is 2019-03-31
, the returned value is 2019-04-01
. When I logged to check t.transaction_date.getTime
it is 1553990400000 (GMT: Sunday, 31 Mar 2019, 0:00:00)
. But the gap for some dates vs getTime is more than one day.
The Date here is a java.sql.Date
I can't figure out how to parse dates correctly in this case in order to get distinct values without any corrections. For the above example I'm expecting to get 2019-03-31
.