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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:44:35+00:00 2026-05-29T14:44:35+00:00

I have a string 12/9/2010 4:39:38 PM which i have to convert to a

  • 0

I have a string "12/9/2010 4:39:38 PM" which i have to convert to a date object. I am using the following code to do it:

String str = "12/9/2010 4:39:38 PM";

DateFormat formatter ;

Date date ;

formatter = new SimpleDateFormat("M/dd/yyyy H:m:s a");

date =(Date)formatter.parse(str);             

System.out.println("date printed"+date);      

However, when im printing the output, i see

Thu Dec 09 04:39:38 IST 2010

How do I get the date exactly the way I declared in the string i.e

12/9/2010 4:39:38 PM

as output? Pls help

  • 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-29T14:44:37+00:00Added an answer on May 29, 2026 at 2:44 pm

    You’re assuming that the Date value itself remembers the format – it doesn’t. Date.toString will do what it wants – because the Date only represents an instant in time.

    If you want to format a Date, use your formatter again:

    System.out.println(formatter.format(date));
    

    However, that won’t necessarily return the exact same value that was in your string, as there may be multiple values which parse the same way. For example, as you’ve only used “H:m:s”, I’d expect “4:5:6” to be parsed the same way as “04:05:06”.

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

Sidebar

Related Questions

I have the following string: NSString *dateStr = @2010-01-15; which I'm trying to convert
I have the following string: 2010-04-08T12:46:43+00:00 I want to convert that to: 8th April
I have the following function using Excel 2010: Private Function MakeAllSheetsValuesOnly(targetBookName As String) If
Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
I have date as a string 16/11/2010 12:00:00 AM for example which I am
I have a Dictionary<string, List<int>> in my code which I am using in the
From a SOAP webservice, a date field is returned as the string: 2010-12-21T08:55:17E-7+01:00 which
I have a data-frame of dates (Date object); see bottom. I'm trying to convert
I'm creating an application using Visual Studio 2010 C#. I have a string in-line
I have following code which on save from the admin area creates a duplicate

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.