Tuesday 31 July 2018

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


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

CalendarDemo.java

import java.util.Calendar;

public class CalendarDemo
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
        System.out.println(cal.getTime());
       
        System.out.println("What day of the month = "+cal.get(Calendar.DATE));
       
        System.out.println("What day of the month = "+cal.get(Calendar.DAY_OF_MONTH));
       
        System.out.println("What day of the week = "+cal.get(Calendar.DAY_OF_WEEK));
       
        System.out.println("What week in month = "+cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
       
        System.out.println("What week in month = "+cal.get(Calendar.WEEK_OF_MONTH));
       
        System.out.println("What day of the year = "+cal.get(Calendar.DAY_OF_YEAR));
       
        System.out.println("What week of the year = "+cal.get(Calendar.WEEK_OF_YEAR));
       
        System.out.println("What hour of the day =  "+cal.get(Calendar.HOUR_OF_DAY));
       
    }
}

Output:

Sun Jul 08 08:50:01 IST 2018
What day of the month = 8
What day of the month = 8
What day of the week = 1
What week in month = 2
What week in month = 2
What day of the year = 189
What week of the year = 28
What hour of the day =  8

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b1e669f4abac38a0eb65bfeb213dca88c58230cc/BasicJava_2018/CalendarDemo_get_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