Wednesday, 31 October 2018

How to use getWeekYear() method of Java.util.GregorianCalendar class


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

GregorianCalendarDemo.java

import java.util.Date;
import java.util.GregorianCalendar;

public class GregorianCalendarDemo
{
    public static void main(String[] args)
    {
        GregorianCalendar cal = (GregorianCalendar) GregorianCalendar
                .getInstance();

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

        /*
         * Returns:
         *
         * the week year represented by this GregorianCalendar. If the
         * ERA value is BC, the year is represented by 0 or a negative
         * number: BC 1 is 0, BC 2 is -1, BC 3 is -2, and so on.
         */

       
        int weekYear = cal.getWeekYear();
        System.out.println("weekYear = "+weekYear);
       
        /*
         * Returns: the Gregorian cutover date for this
         * GregorianCalendar object.
         */

        Date date = cal.getGregorianChange();
        System.out.println(date);
    }
}

Output

Fri Sep 21 09:59:22 IST 2018
weekYear = 2018
Fri Oct 15 05:30:00 IST 1582

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

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

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