简体   繁体   中英

how to set time interval of 1.5 hours?

In the following code the time interval is of 1 hour but I want a time interval of 1.5 hour. For example 8:30-10:00. What am I doing wrong? or is there any Java library which can help me set my desired time interval of 1.5 hour?

private static void createLectureTime()
{
    for (int i=8; i<16; i++)
    {           
        lectureTimings.add(i+":30"+" TO "+(i+1)+":00");             
    }
}

You can use Calendar class to solve this problem.Here is the code.

long startTime = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(startTime);
calendar.add(Calendar.MINUTE, 90);
System.out.println(calendar.getTime());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM