0

Hi,
I'm trying to understand how the Calendar, GregorianCalendar and Locale classes work.

Say I instantiate two Locale objects and then two Calendar objects, each with their respective Locale.

Then ask for the always troublesome DAY_OF_WEEK on every Calendar object as in the following code:

import java.util.Calendar;
import java.util.Calendar.*;
import java.util.*;


class Calendario {
	public static void main(String[] args) {
		
		Locale there = new Locale("ENGLISH", "US");
		Locale here = new Locale("GERMAN", "DE");
		
		
		GregorianCalendar gCalThere = new GregorianCalendar(there);
		GregorianCalendar gCalHere = new GregorianCalendar(here);		
		
		System.out.println("Day of week today there: " + gCalThere.get(GregorianCalendar.DAY_OF_WEEK));
		System.out.println("Day of week today here: " + gCalHere.get(GregorianCalendar.DAY_OF_WEEK));
		
		
	}
}

The output is the following:

Day of week there: 4
Day of week here: 4

Being today wednesday, I'd have thougth "Day of week here" should be "3".

Why isnt'? How can I properly change Locale and display the correct day of the week?
Thanks in advance.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by freelancelote
0

In many (most?) locales, Sunday is the first day of the week, thus Wednesday is the fourth. From the Calendar.java source:

/**
     * Value of the {@link #DAY_OF_WEEK} field indicating
     * Wednesday.
     */
    public final static int WEDNESDAY = 4;

You can set the first day of week to be whatever you want on your calendar object with setFirstDayOfWeek(int) (whether you should is another question altogether).

0

Hi, thanks Ezzaral.
Yeah, you are right, fiddeling with setFirstDayOfWeek(int) sounds messy.
I was trying to find a way to change the Locale and hoping that all the rest would change automatically (that was the attempt of the code I showed, anyway).
Any ideas on how to do that?
thanks,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.