Results 1 to 2 of 2
  1. #1
    bczm8703 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default How to use java Date object??

    hi... my code is as below

    Java Code:
    String sDate="12-09-2008 1200 ";
            DateFormat dateformatter = new SimpleDateFormat("dd-MM-yyyy HHmm");
            Date transDate;
    
     try
            {
                transDate=dateformatter.parse(sDate);
    
                System.out.println(transDate.toString());
            }
    with the codes above i saw this:
    Java Code:
    Fri Sep 12 12:00:00 SGT 2008
    but the output that i would like to have see for the println() shld be something like this:
    Java Code:
    12-09-2008 1200
    is this possible??

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default

    Use the same SimpleDateFormat to format(...) the Date.

    Understand that a java.util.Date is an encapsulation of an instant in time. The toString() method represents this instant in a human-readable, locale dependent way. Read the documentation.

    db

Similar Threads

  1. Clear the Date object for cron
    By soichi in forum New To Java
    Replies: 3
    Last Post: 01-24-2011, 12:21 PM
  2. Calendar object? - Getting date from user
    By hiei_yasha in forum New To Java
    Replies: 9
    Last Post: 01-23-2011, 03:58 AM
  3. Problem with Date Object
    By R O C K Y in forum Advanced Java
    Replies: 4
    Last Post: 02-15-2009, 04:37 PM
  4. Replies: 2
    Last Post: 12-03-2008, 11:14 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 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
  •