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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:16:30+00:00 2026-06-16T22:16:30+00:00

I have a date string 2012-01-26 which I get from JSON. I have to

  • 0

I have a date string “2012-01-26” which I get from JSON.

I have to now check if the month and year is as current year than display data it in ListView.

SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-DD");
  try {
      Calendar c = Calendar.getInstance(); 
      c.setTime(dateFormat.parse(event_start_date));
      int month = c.get(Calendar.MONTH);
      System.out.println(c.get(Calendar.YEAR));
      System.out.println("month is"+month);
 }

Year value is always correct, but the Month is always zero.What am I missing guys?

  • 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-16T22:16:31+00:00Added an answer on June 16, 2026 at 10:16 pm

    You are fetching month using Calendar’s instance.

    int month = c.get(Calendar.MONTH);
    

    So you will get current month (i.e. January)
    And it means 0. So the result is correct.

    Check this.

    month – The month that was set (0-11) for compatibility with Calendar.

    If you want the month of event_start_date, then you won’t have to use calendar’s instance at all.

    You can fetch it using

    int month = event_start_date.getMonth();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a date string 2012-11-21 13:11:25 which I get from local database.
I have a jArray and a string from that jArray, message2: [{date:2012,count:1,message : message1},
I have a string which returns the date and time as 2012-11-08 12:45:30 .
I have the following string i need to parse to a date: 2012-01-31T08:41:12.5462495+01:00 now
I have a String which contains date in the format dd/mm/yyyy . For example
I have the following code, which reads the date and time from some DateTimePickers
I have a string something like: foo title:2012-01-01 bar Where I need to get
I have an array which looks like this: array(10) { [0]=> string(10) 2012-11-03 [1]=>
Can anyone help me, i have a string which passes date as (YY-mm-dd) eg.
I have a string which is allways in this format: 7 May 2012 or

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.