Find Remaining day and time using jodatime

前端 未结 2 1758
说谎
说谎 2021-01-19 11:58

I want to compare(finding remaining days and time between two days) using joda time. I am taking two DateTime object like this(one is starting and another is ending)

2条回答
  •  轮回少年
    2021-01-19 13:04

    If you want the output in prettier format then you can use this snippet too

    val startDate = DateTime.now()
    val endDate = DateTime(endTime)
    val period = Period(startDate, endDate)
    
    val periodFormatter = PeriodFormatterBuilder().apply {
        when {
            period.days > 0 -> appendDays().appendSuffix(" day", " days")
            period.hours > 0 -> appendHours().appendSuffix(" hour", " hours")
            period.minutes > 0 -> appendMinutes().appendSuffix(" minute", " minutes")
        }
    }.toFormatter()
    
    periodFormatter.print(period)
    

提交回复
热议问题