difference in seconds between two dates using joda time?

前端 未结 2 1853
春和景丽
春和景丽 2020-12-01 23:28

Suppose there are two dates A(start time) & B(end time). A & B could be the time on the same day or even different day. My task is to show difference in seconds. Dat

2条回答
  •  失恋的感觉
    2020-12-01 23:44

    Use the Seconds class:

    DateTime now = DateTime.now();
    DateTime dateTime = now.plusMinutes(10);
    Seconds seconds = Seconds.secondsBetween(now, dateTime);
    System.out.println(seconds.getSeconds());
    

    This piece of code prints out 600. I think this is what you need.

    As further advice, explore the documentation of joda-time. It's pretty good, and most things are very easy to discover.

    In case you need some help with the parsing of dates (It's in the docs, really), check out the related questions, like this:

    Parsing date with Joda with time zone

提交回复
热议问题