Results 1 to 2 of 2
  1. #1
    ironballs is offline Member
    Join Date
    Aug 2007
    Rep Power

    Default Date as String to TimeStamp

    I'm trying to convert date & time presented in String to TimeStamp object (so it could be written to DB).
    I've created a small program to test this, but the problem is, that every time, when I check the resulting Timestamp object the date part always resets to '01' - it's the same thing when writtne to the DB:

    String t2,st = "16/08/2007 09:04:34";
    SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss");
    Date date = sdf.parse(st);
    Timestamp timestamp = new Timestamp(date.getTime());
    t2 = timestamp.toString();
    // T2 will show: "2007-01-16 09:04:34.0"

    anyone knows how to solve this issue ?


  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    England, Bath
    Rep Power


    change the first mm to MM as mm represents minutes not Month which is represented by MM

Similar Threads

  1. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  2. Timestamp in SQL format
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 12:37 PM
  3. Converting Epoch to string Date
    By amyedwards in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 11:33 PM
  4. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  5. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts