Android之判断时间戳是不是今天
生活随笔
收集整理的這篇文章主要介紹了
Android之判断时间戳是不是今天
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 需求
判斷時間戳是不是今天
2、工具代碼
/*** 獲取每日0點時間* @return*/fun getTodayTime(timeStamp: Long): Long {val cal = Calendar.getInstance()cal.timeInMillis = timeStampcal.set(Calendar.HOUR_OF_DAY, 0)cal.set(Calendar.SECOND, 0)cal.set(Calendar.MINUTE, 0)cal.set(Calendar.MILLISECOND, 0)return cal.timeInMillis}fun isToday(time: Long): Boolean {val sdf = SimpleDateFormat("yyyy-MM-dd")val date = Date(time)return try {val old = sdf.parse(sdf.format(date))val now = sdf.parse(sdf.format(Date()))val oldTime = old.timeval nowTime = now.time總結
以上是生活随笔為你收集整理的Android之判断时间戳是不是今天的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之网络请求通过协程+okh
- 下一篇: Android之Fatal Except