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

The Archive Base Latest Questions

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

I have timestamp read from database into a string as below: Source database table

  • 0

I have timestamp read from database into a string as below:

Source database table timestamp field value is as below:

8/21/2012 2:09 AM

I am reading above timestamp into a String field in a java program.

However, while writing it into destination database table, I am reconverting the String back into time stamp using below code:

java.text.DateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date newDate = format.parse(item.getMyTimeStamp());
ps.setTimestamp(1, new java.sql.Timestamp(newDate.getTime()));

However, the timestamp field value in the destination table is coming as below:

8/21/2012 12:00 AM

As clear the hour field is getting reset to 12 AM.

How can I retain the original timestamp value?

  • 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-16T20:45:08+00:00Added an answer on June 16, 2026 at 8:45 pm

    @Nikunj this new java.text.SimpleDateFormat("yyyy-MM-dd"); is literally losing your timestamp…so it sets the time into 12AM…. you need to get the precise format.

    Can you please try this, Assuming your string contains the correct date from source database,

    String sourceDate = "8/21/2012 2:09";
    Timestamp sourceTS = Timestamp.valueOf(sourceDate);
    System.out.println(sourceTS.getNanos());
    

    Here is the post: Convert Java String to sql.Timestamp.

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

Sidebar

Related Questions

I have a Timestamp field in a WebSQL database that is stored like: /Date(1340420400000)/
My database table have a Timestamp column named as inTime and i am using
In my Postgresql database, I have a timestamp without time zone with this value
Currently I have a timestamp for example say, 2012-06-23 14:24:07.975 and two times -
I have a UTC timestamp. I want to convert it into YYYY/MM/DD format in
I have a Sqlite notes database with a Toxi schema (Notes table, Tags table,
I have a table of non trivial size on a DB2 database that is
I have this date in a PostgreSQL 9.1 database in a timestamp without time
I have a TIMESTAMP in the database for pages, so in this format $d=2011-01-03
I am experimenting with Mongodb and NoRM in C#. From what I have read

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.