How do I get difference between two dates in android?, tried every thing and post

后端 未结 11 2290
天命终不由人
天命终不由人 2020-11-28 09:06

I saw all the post in here and still I can\'t figure how do get difference between two android dates.

This is what I do:

long diff = date1.getTime()          


        
11条回答
  •  感动是毒
    2020-11-28 09:56

    written in Kotlin: if you need difference between 2 dates and don't care about the dates itself ( good if you need to do something in the app,based on time from other operation time that was saved in shared preferences for example). save first time :

    val firstTime:Long= System.currentTimeMillis()
    

    save second time:

    val now:Long= System.currentTimeMillis()
    

    calculate the miliseconds between 2 times:

    val milisecondsSinceLastTime: Long =(now-lastScrollTime)
    

提交回复
热议问题