Click here to Skip to main content
16,021,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to increment only the time in a date by 1 hour.

Java
Calendar cal=Calendar.getInstance();
cal.setTime(Calendar.HOUR,1);
cal.getTime();


This is the code I tried to increment time,but this also increments date with it.
Can anybody help me to solve this?
Posted
Updated 9-Mar-15 3:52am
v2

1 solution

Try this:
C#
package com.peterleow;

import java.util.Calendar;

public class exercise1 {

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();

        System.out.println(calendar.getTime());

        calendar.add(Calendar.HOUR,  1);

        System.out.println(calendar.getTime());

    }

}

Read more: Class Calendar[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900