1. Are you ready for the Galaxy S20? Here is everything we know so far!

Creating typeconvertor to convert Int timestamp to LocalDate

Discussion in 'Android Development' started by Murphler, May 10, 2021.

  1. Murphler

    Murphler Lurker
    Thread Starter

    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
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Creating typeconvertor convert
  1. mysorian
    Replies:
    0
    Views:
    212
  2. mysorian
    Replies:
    0
    Views:
    288
  3. Kuldip Somwanshi
    Replies:
    0
    Views:
    320
  4. Davide Vergnani
    Replies:
    0
    Views:
    315
  5. xpressive
    Replies:
    0
    Views:
    505
  6. Nabeel Rajabali
    Replies:
    1
    Views:
    639
  7. androinewbi
    Replies:
    6
    Views:
    969
  8. MackOS
    Replies:
    0
    Views:
    437
  9. Youssef Hammad
    Replies:
    0
    Views:
    1,164
  10. App Update
    Replies:
    1
    Views:
    352

Share This Page

Loading...