The correct way to set and get hour, minutes, sec

前端 未结 2 1186
鱼传尺愫
鱼传尺愫 2020-12-19 05:32

I am trying to get some information out of a database and then using that information to get some statistics.

I want to get statistics based on an interval of hours,

2条回答
  •  自闭症患者
    2020-12-19 06:23

    Using the java.util.Calendar

    Calendar c = Calendar.getInstance();
    c.set(Calendar.DATE, 2);
    c.set(Calendar.HOUR_OF_DAY, 1);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    

    Or use Joda Time http://joda-time.sourceforge.net/.

提交回复
热议问题