Tuesday, 31 July 2018

How to set different calendar fields values using set method of Java.util.calendar class


Click here to watch on Youtube:
https://www.youtube.com/watch?v=fIdAgdsbjzQ&list=UUhwKlOVR041tngjerWxVccw

CalendarDemo.java

import java.util.Calendar;

public class CalendarDemo
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
        System.out.println("Before Set = " + cal.getTime());

        cal.set(Calendar.HOUR, 10);
        cal.set(Calendar.MINUTE, 29);
        cal.set(Calendar.SECOND, 22);

        System.out.println("After Set  = " + cal.getTime());

        System.out.println("Hour = " + cal.get(Calendar.HOUR));
        System.out.println("Min = " + cal.get(Calendar.MINUTE));
        System.out.println("Sec = " + cal.get(Calendar.SECOND));

    }
}

Output

Before Set = Sun Jul 08 09:01:59 IST 2018
After Set  = Sun Jul 08 10:29:22 IST 2018
Hour = 10
Min = 29
Sec = 22

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_set_cal_fields_value.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_set_cal_fields_value

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_set_cal_fields_value/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a comment