• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Creating typeconvertor to convert Int timestamp to LocalDate

Murphler

Lurker
May 1, 2021
2
0
What would be the best way to go about this. I am using 2 different APIs and one returns a date as a String and the other returns date as an Int timestamp in the format of e.g. 162000360

I was using the ThreeTen backport for Date/Time classes. I have successfully created a type convertor for the date I get back as a String - provided below

@TypeConverter
@JvmStatic
fun stringToDate(str: String?) = str?.let {
LocalDate.parse(it, DateTimeFormatter.ISO_LOCAL_DATE)
}

@TypeConverter
@JvmStatic
fun dateToString(dateTime: LocalDate?) = dateTime?.format(DateTimeFormatter.ISO_LOCAL_DATE)


I'm struggling to replicate the same for the Int timestamp as the DateTimeFormatter requires a String passed into it and won't allow an Int. Any help is much appreciated
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones