I have a Date Fri Jun 28 10:00:01 GMT+01:00 2024
which I want to convert to Epoch milis to send to the backend.
I have tried the following
fun Dates.toEpochMillis(timeZoneId: ZoneId): Long {
val one = Instant.ofEpochMilli(time).toEpochMilli() // 1719565201000
val three = secsToMillis(this.toLocalDateTime(timeZoneId).utcEpochSecs) // 1719568801000
return one
}
fun Dates.toLocalDateTime(timeZoneId: ZoneId): LocalDateTime {
return Instant.ofEpochMilli(time).atZone(timeZoneId).toLocalDateTime()
}
fun secsToMillis(timeInSecs: Long): Long {
return timeInSecs * 1000
}
which of the above is correct, or if you suggest any other way of doing this please?
Note: I am not using this value to display but to send it to backend.
thanks
R