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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:34:31+00:00 2026-06-15T05:34:31+00:00

i am getting problem from extracting month and year from data object. String strdate

  • 0

i am getting problem from extracting month and year from data object.

String strdate = "2012-11-07T13:28:23";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
// Date date = dateFormat.parse(strdate);
Date date = new Date();
System.out.println(date.getDate());
System.out.println(date.getYear());
System.out.println(date.getMonth());
System.out.println(date);

my output is like

28
112
10
Wed Nov 28 15:37:30 IST 2012

what is wrong here ?

  • 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-06-15T05:34:32+00:00Added an answer on June 15, 2026 at 5:34 am

    what is wrong here ?

    Your compiler should be telling you what’s wrong via warnings: you’re using deprecated methods on Date, to start with. Don’t ignore those warnings.

    You should be using Calendar to get day/month/year etc values, as a Calendar has an associated calendar system and time zone, both of which are required in order to get sensible values out.

    Next there’s the problem that you’re just getting the current date and time instead of using strdate and dateFormat:

    // Date date = dateFormat.parse(strdate);
    Date date = new Date();
    

    new Date() always returns the current date/time as reported by the system.

    However, if you’re confused by the 112 and the 10, you should read the documentation for the methods you’re calling, which explains that getYear() returns a year based on 1900 (so a return value of 112 means the year is 2012), and getMonth() returns a 0-based month (so January=0). Always read the documentation for methods you’re calling, especially if you think they’re giving you odd results.

    Ideally, however, you should use Joda Time instead – it’s a far more sensible date/time API than the built-in one.

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

Sidebar

Related Questions

The problem is getting data in my dataGridView from my webservice. When i invoke
I'm new to SQL. I have a simple problem with getting the results from
I have a problem getting data from the server. server is my localhost. SMutableURLRequest
I am having a problem getting this code to work. Basically I Go from
Greetings! I'm having a problem getting a text value of a captcha from a
I have a problem with getting a class from an external .jar file. I
I have a problem with getting jquery to retrieve results from a WCF service.
i am getting problem as i have some data in a database tabel file
can you suggest me the shortest and easiest way for extracting substring from string
I'm using Stroustrup's swan book. I have run into a problem getting output from

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.