Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7581531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:13:36+00:00 2026-05-30T18:13:36+00:00

I am writing a class to simplify all the operations that I could make

  • 0

I am writing a class to simplify all the operations that I could make with a GregorianCalendar.
The operations that I need to make are:
-Getting the date in string format, translated to Italian;
-Making the subtraction between two dates.
I havent’ used Calendar,Date and Time classes because they have a lot of deprecated methods.
Also, the tag isn’t gregoriancalendar because I may need to use another class (but feel free to modify it if not agree).
However this is the class:

package TruckingCompany;

import java.util.GregorianCalendar;
import java.util.Locale;

@SuppressWarnings("serial")
public class TCCalendar extends GregorianCalendar
{
public TCCalendar()
{
    super(Locale.ITALY);
}
@Override
public String toString()
{
    String str=new String();
    switch(get(DAY_OF_WEEK))
    {
        case 1: 
            str+="Domenica "; 
            break;
        case 2:
            str+="Lunedì ";
            break;
        case 3:
            str+="Martedì ";
            break;
        case 4:
            str+="Mercoledì ";
            break;
        case 5:
            str+="Giovedì ";
            break;
        case 6:
            str+="Venerdì ";
            break;
        case 7:
            str+="Sabato ";
            break;
    }
    str+=get(DAY_OF_MONTH);
    switch(get(MONTH))
    {
        case 0:
            str+=" Gennaio ";
            break;
        case 1:
            str+=" Febbraio ";
            break;
        case 2:
            str+=" Marzo ";
            break;
        case 3:
            str+=" Aprile ";
            break;
        case 4:
            str+=" Maggio ";
            break;
        case 5:
            str+=" Giungo ";
            break;
        case 6:
            str+=" Luglio ";
            break;
        case 7:
            str+=" Agosto ";
            break;
        case 8:
            str+=" Settembre ";
            break;
        case 9:
            str+=" Ottobre ";
            break;
        case 10:
            str+=" Novembre ";
            break;
        case 11:
            str+=" Dicembre ";
            break;
    }
    str+=get(YEAR)+ " Ore ";
    str+=get(HOUR_OF_DAY)+ ":";
    str+=get(MINUTE)+":";
    str+=get(SECOND);
    return str;
}
}

I use linux and the time is correctly set to 10:19 (Italian hour).
But now (at 10:20 local hour) I get as result of the toString method:
“Venerdì 2 Marzo 2012 Ore 13:21:10”
Don’t look at the Italian stuff, the problem is the hour: get(HOUR_OF_DAY) returns 13 instead of 10 (22:21).
Also, there is another class more intuitive? I have searched in javadoc and except Calendar,GregorianCalendar, Date and Time I haven’t found anything else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:13:38+00:00Added an answer on May 30, 2026 at 6:13 pm

    The problem is most likely with the

    super(Locale.ITALY)

    It will
    Constructs a GregorianCalendar based on the current time in the “default time zone” with the given locale.

    You will most probably need to change the TIMEZONE too.

    I would use this one:

    GregorianCalendar(TimeZone zone, Locale aLocale)

    Reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm busy writing a class that monitors the status of RAS connections. I need
Im writing a class that replaces all input type=button and input type=submit in the
I'm currently writing a class that implements the SeekableIterator interface and have run into
I'm currently writing a class to handle all database-activity in my application, and so
I'm writing a class-library in VB.Net and one of the subs that are being
I am writing a class that is linked to an external resource. One of
I am writing a class that I know that needs a lock, because the
I'm writing a class in C++ that I cannot debug by using F5. The
I am writing a class in Python 2.6.2 that contains a lookup table. Most
I`m writing class. Here is one of functions: public string GetAttribute(string attrName) { try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.