I have an app on iOS and am working on porting over to android. I am having an issue with handling the time.
On iOS I store points of time using:
Int(NSDate().timeIntervalSince1970-0.5)
and Convert it to HH:MM:SS using:
private let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm:ss"
return dateFormatter.string(from: Date(timeIntervalSince1970: value))
On Android(Kotlin) to store the point of time I use: System.currentTimeMillis()/1000
And for conversion:
LocalTime.MIN.plus(Duration.ofSeconds(xVal)).toString())
The issue is that the value after being converted is 6 hours ahead(could be more or less but I only look at the HH:MM:SS). As far as I can tell, the way that I get the time on android is correct and I think the issue lies in when I am converting it. I have looked around for more methods of converting time since an an interval to time of day but I could not get it to work. Most posts are just converting seconds to HH:MM:SS and so those are right out of the question. What would the equivalent to my iOS code be?
EDIT I've also tried using this method to convert it still is 6 hours off even though I am giving it a timezone:
val cal = Calendar.getInstance()
cal.timeInMillis = xVal * 1000L
cal.timeZone = TimeZone.getTimeZone(TimeZone.getDefault().displayName)
Log.i("This is the cal value",cal.get(Calendar.HOUR_OF_DAY).toString())