Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: get(GregorianCalendar.DAY_OF_WEEK)

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default get(GregorianCalendar.DAY_OF_WEEK)

    [ code = java ]
    import java.util.GregorianCalendar;
    public class Aries {

    public static void main(String[] args) {
    GregorianCalendar c = new GregorianCalendar(2019, 5, 7);
    System.out.println("Day:" + c.get(GregorianCalendar.DAY_OF_WEEK));
    }
    }
    [/code]
    Hi, can anyone explain why this output is 6 instead of 3? Based on this list it should be 3.
    Days of week are represented as:
    SUNDAY = 1
    MONDAY = 2
    TUESDAY = 3
    WEDNESDAY = 4
    THURSDAY = 5
    FRIDAY = 6
    SATURDAY = 7
    Thank you

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: get(GregorianCalendar.DAY_OF_WEEK)

    You will get Day 3 if you use GregorianCalendar() without passing any parameters to it.

    • GregorianCalendar() - initializes the object with the current date and time in the default locale and time zone
    • GregorianCalendar(int year, int month, int dayOfMonth) - initializes the object with the date-set passed as parameters in the default locale and time zone

    There are totally two different things.
    Last edited by John Joe; May 7th, 2019 at 01:16 AM.
    Whatever you are, be a good one

Similar Threads

  1. Replies: 5
    Last Post: August 10th, 2013, 12:29 PM
  2. GregorianCalendar problems
    By Crixus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2011, 10:19 AM
  3. [SOLVED] GregorianCalendar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 30th, 2009, 04:30 AM

Tags for this Thread