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 5944345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:31:28+00:00 2026-05-22T16:31:28+00:00

I am using GregorianCalander and when i tried to get todays date using the

  • 0

I am using GregorianCalander and when i tried to get todays date using the following code i am getting a date which is backdated to one month. The code i have used is as follows.

        Calendar gcal = new GregorianCalendar();
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        today = getTime(gcal);
        //date = dateFormat.format(calendar.getTime());
        System.out.println("Today: " + today);

Please help me to solve this issue.

The output is :

Today: Thu Apr 28 00:00:00 NZST 2011

EDIT

private Date getTime(Calendar gcal) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String day = form_helper.round(gcal.get(GregorianCalendar.DAY_OF_MONTH));
        String month = form_helper.round(gcal.get(GregorianCalendar.MONTH));
        String year = form_helper.round(gcal.get(GregorianCalendar.YEAR));
        String date = day + "/" + month + "/" + year;
        System.out.println(sdf.parse(date));
        return sdf.parse(date);
    } catch (ParseException ex) {
        Logger.getLogger(timesheet_utility.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
  • 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-22T16:31:28+00:00Added an answer on May 22, 2026 at 4:31 pm

    I think internal numbering of months starts with 0, not 1. So, you probably need to somewhere add +1.
    Edit: after you showed some more code: The needed change is

    String month = form_helper.round(gcal.get(GregorianCalendar.MONTH) + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using android 2.3.3, I have a background Service which has a socket connection. There's
I have a list of specific objects(meetings) which I need to group using a
I realized this: Calendar c = new GregorianCalendar(); mYear=c.get(Calendar.YEAR); mMonth=c.get(Calendar.MONTH); mDay=c.get(Calendar.DAY_OF_MONTH); And this: Date
The following code creates a two radio buttons. Each option contains a date value
I have a custom UserType which stores a date/time value in a TIMESTAMP field
I have the following date: 2011-10-07T08:51:52.006Z Now I want to parse it into a
I have a JSpinner using a SpinnerDateModel which has a start at Jan 1,
Using MVC2 I have an AJAX form which is posting to a bound model.
Using online interfaces to a version control system is a nice way to have

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.