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

  • Home
  • SEARCH
  • 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 8505111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:13:36+00:00 2026-06-11T02:13:36+00:00

I am trying to do a simple String to Date conversion in Java. I

  • 0

I am trying to do a simple String to Date conversion in Java. I am skimming the date off some logs and need to convert it to a date to do some processing. A date coming through will look like this:

2012-09-07 19:53:33

In my code when I try to convert this into a Date object I get a completely different date. My code looks like this:

String taskStart = "2012-09-07 19:53:33";  
String dateFormat = "yyyy-MM-dd hh:MM:ss";
SimpleDateFormat dateFormat=new SimpleDateFormat(format);
Date taskStartDate = dateFormat.parse(taskStart); 

The output I get is this:

Sat May 07 19:00:27 PDT 2016

How can I just simply convert my original date to the correct format??

  • 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-11T02:13:37+00:00Added an answer on June 11, 2026 at 2:13 am
    1. You’ve specified MM (month in year) twice. The m’s for “minute” must be lowercase.
    2. If you’re taking 24-hour based times, you need to specify HH in order to capture hours that are specified in the range of 0-23, as opposed to hh which expects AM/PM hours (hours in the range of 1-12 with an AM/PM specifier as part of the time string)
    3. Finally, your example code doesn’t define the format variable that you’re passing into the constructor for your SimpleDateFormat object. In fact, you’re using the variable name dateFormat twice and not defining the format variable at all – at least not according to the code that you included in the question.

    So, your proper format string, I believe, should be…

    "yyyy-MM-dd HH:mm:ss"
    

    …and the full, proper code example would be:

    String taskStart = "2012-09-07 19:53:33";  
    String format = "yyyy-MM-dd HH:mm:ss";
    SimpleDateFormat dateFormat=new SimpleDateFormat(format);
    Date taskStartDate = dateFormat.parse(taskStart); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a parameter of type string to a date time. I'm
I am trying to send a simple string from One viewcontroller to another viewcontroller
I'm trying to extract a simple string from the HTML response. The response looks
I am trying to add an attribute using javax.xml.bind.annotation to a simple type (String
I'm trying to bind a simple one-line string to a textbox's text property but
I'm trying to use a simple HTTP get to load a string from a
I'm trying to do a simple caesarian shift on a binary string, and it
What I'm trying to do is fairly simple. The user inputs a string. The
So, I have a simple class where I am trying to save a string
I'm trying to create a simple date class, but I get an error on

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.