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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:25:17+00:00 2026-05-31T02:25:17+00:00

When I create a Date from parsing a String and access the day of

  • 0

When I create a Date from parsing a String and access the day of the month, I get the wrong value.

Date datearr = null;
DateFormat df1 = new SimpleDateFormat("dd-MM-yyyy");
String dataa = "17-03-2012";
try {
    datearr = df1.parse(dataa);
} catch (ParseException e) {
    Toast.makeText(this, "err", 1000).show();
}

int DPDMonth = datearr.getMonth() + 1;
int DPDDay = datearr.getDay();
int DPDYear = datearr.getYear() + 1900;

System.out.println(Integer.toString(DPDDay)+"-"+Integer.toString(DPDMonth)+"-"+Integer.toString(DPDYear));

Why do I get 0 instead of 17?

03-11 10:24:44.286: I/System.out(2978): 0-3-2012
  • 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-31T02:25:18+00:00Added an answer on May 31, 2026 at 2:25 am

    Here’s a snippet the doesn’t use deprecated methods anymore, fixes naming issues and simplifies the output.

        Date datearr = null;
        DateFormat df1 = new SimpleDateFormat("dd-MM-yyyy");
        String dataa = "17-03-2012";
        try {
            datearr = df1.parse(dataa);
        } catch (ParseException e) {
            Toast.makeText(this, "err", 1000).show();
            return;  // do not continue in case of a parse problem!!
        }
    
        // "convert" the Date instance to a Calendar
        Calendar cal = Calendar.getInstance();
        cal.setTime(datearr);
    
        // use the Calendar the get the fields
        int dPDMonth = cal.get(Calendar.MONTH)+1;
        int dPDDay = cal.get(Calendar.DAY_OF_MONTH);
        int dPDYear = cal.get(Calendar.YEAR);
    
        // simplified output - no need to create strings
        System.out.println(dPDDay+"-"+dPDMonth+"-"+dPDYear);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript you can create a Date object from a string, like var mydate
From an external service I get objects with Date+Time fields as String 's in
We can't use java.text.SimpleDateFormat, so is there any way to create date object from
I'm looking to create a custom date picker with code examples from several sources.
What does it mean when you get or create a date in UTC format
I'm parsing this date format from XML:=> 2011-12-06T07:41:14.016+00:00 , and I'm getting this error:
I want to create a view from the following two tables: Entry: entry_id entry_date
im trying to formatting the date field 'created_at' from Twitter API response with Zend_Date.
I find it curious that the most obvious way to create Date objects in
How can I create a date object which is less than n number of

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.