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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:07:16+00:00 2026-06-17T23:07:16+00:00

I am tryig to convert birthday from String to Date in order to add

  • 0

I am tryig to convert birthday from String to Date in order to add to the arraylist contacts. Then read from the contacts to display the birthday. However 05/02/1990 becomes 365/12/1990, 06/12/1991 becomes 365/12/1991 (i.e. DD and MM are incorrect). Thank you very much for the help!

ArrayList<Person> contacts = new ArrayList<Person>();
...
String firstName = sc.next();
String lastName = sc.next();
String email = sc.next();
String birthdayStr = sc.next();
SimpleDateFormat formatter = new SimpleDateFormat("DD/MM/YYYY");
try{

    Date birthday = formatter.parse(birthdayStr); 
    Person s = new Person(firstName, lastName, email, birthday);
    contacts.add(s);
    Date b = s.getBirthday();
    System.out.println(formatter.format(b));

}catch(ParseException e){

   System.out.println( e.getMessage());
}
  • 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-17T23:07:17+00:00Added an answer on June 17, 2026 at 11:07 pm

    D is day in year, you need lowercase d for day of month. Use lowercase y also.

    new SimpleDateFormat("dd/MM/yyyy")
    

    The use of uppercase Y relates to week year:

    A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.

    For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997.

    To avoid this "side effect" on the year, lowercase y can be used.

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

Sidebar

Related Questions

How to extract and save array from string parameter? I'm trying convert string beafore_create
Am trying to convert my string value(the value is millisecond value) from seconds. Here
I'm trying to convert a string into a date format My string looks like
Trying to convert a string of binary inputs into a vector of ints. I'd
Trying to convert output from a rest_client GET to the characters that are represented
Trying to convert int arrays to string arrays in numpy In [66]: a=array([0,33,4444522]) In
im trying to convert a date format into a new format in this example
Im trying to convert unixtime to date but the results im getting are wrong
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
am trying convert string to float,when i am passing single char it is giving

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.