Kotlin date time comparison

332 Views Asked by At

I am trying to figure out how this works. My initial date is: "2022-11-06T08:39:16.307Z"

So now I did this:

 val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
 sdf.timeZone = TimeZone.getTimeZone("UTC")
 val time: Long = sdf.parse("2022-11-06T08:39:16.307Z").time
 val calendar = Calendar.getInstance()
 val currentTime = calendar.timeInMillis
 val diff = (currentTime - time) / 1000

Difference is negative number but it should be positive as other date is in past. Yes I hate working with dates in general but can not figure out why it works like this.

0

There are 0 best solutions below