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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:02:49+00:00 2026-05-31T08:02:49+00:00

All this is my program where i am trying the folowing Below is my

  • 0

All this is my program where i am trying the folowing

Below is my code for Dates functionality…

import java.text.SimpleDateFormat;
import java.util.*;
import java.text.*;
public class DateToCalender {
public static void main(String args[]){
//String strFormat="yyyymmdd";

//DateFormat myDateFormat = new SimpleDateFormat(strFormat);
DateFormat df= new SimpleDateFormat("yyyyMMdd");
df.setLenient(false);
Calendar start=Calendar.getInstance();
try {
Date fromDt =(Date)df.parse("20111207");
//Date myDate = new Date();
//myDate = (Date)myDateFormat.parse("20111207");
//myGDate.setTime(myDate);
start.setTime(fromDt);

                start.set(Calendar.MONTH,(start.get(Calendar.MONTH)+1));
System.out.println(start);

System.out.println(start.get(Calendar.YEAR));
System.out.println(start.get(Calendar.MONTH)-1);
System.out.println(start.get(Calendar.DAY_OF_MONTH));
//System.out.println("From My class"+myGDate.get(Calendar.MONTH));

//System.out.println("From My class new month"+(myGDate.get(Calendar.MONTH)+1));

} catch (ParseException e) {
System.out.println("Invalid Date Parser Exception ");
e.printStackTrace();
}
} 
}  

when iam executing this code iam getting folowwing o/p

java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA
=1,YEAR=2011,MONTH=12,WEEK_OF_YEAR=50,WEEK_OF_MONTH=2,DAY_OF_MONTH=7,DAY_OF_YEAR=341,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=19800000,DST_OFFSET=0]
2011
0
7

**
issue is :

Though iam entering date as 2011/12/07
            I am getting     year as 2011
                             month as 0
                             date as 7
Can some one help in resolving above issue

Could any body please let me know , how this can be resolved .

  • 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-31T08:02:50+00:00Added an answer on May 31, 2026 at 8:02 am

    Don’t subtract 1 from the month; Calendar already knows that it’s zero-based.

    It seems to me like you’re doing far too much work here. Why can’t you just do this?

    private static final DateFormat DEFAULT_DATE_FORMAT;
    
    static {
        DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
        DEFAULT_DATE_FORMAT.setLenient(false);
    }
    
    
    
    public Calendar getCalendar(String dateAsString) {
        Calendar value = Calendar.getInstance();
        Date d = DEFAULT_DATE_FORMAT.parse(dateAsString);
        value.setTime(d);
        return value;
    }
    

    There’s an exception that needs to be added to the method signature, but you get the idea. Look at the Calendar javadocs. This could be easier.

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

Sidebar

Related Questions

I am trying to solve a problem. This program contains all the edge in
I'm trying to use my variable in all files of my program. this is
Dear all,Now i have this question in my java program,I think it should be
When trying to run the following program code, this error occurred; Input string was
I normally program in C++, so all this DataSource/DataSet/Binding stuff is confusing the hell
Ok, so, im having trouble with this program im writing, it all seems to
This is all in the context of a larger program, so Im going to
Can someone help me with this: This is a program to find all the
In the following scenario, I was trying to see how to handle this code
i've been trying to link mysql with c++ below is the code for ref

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.