Results 1 to 2 of 2
  1. #1
    garinapavan is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

    Default DateObject with the currentdate and Time specified by me

    Iam getting the Timestamp from the data base and picking up the time from that :


    and now i need to get the Date object with current date and with the above time.

    I see that the Date object gives current date and time.

    Can anybody suggest some thing for this.

    Regards
    Navap.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    import java.text.*;
    import java.util.*;
    
            // Prepare a formatter. See SDF api for options.
            DateFormat df = new SimpleDateFormat("HHmm ddMMMyyyy");
            // Get a Calendar instance.
            Calendar calendar = Calendar.getInstance();
            System.out.println("now = " + df.format(calendar.getTime()));
            // Get the time. Assume time is in 24 hour format.
            String timeStr = "0612";  // 6:12 am
            int hours = Integer.parseInt(timeStr.substring(0,2));
            int minutes = Integer.parseInt(timeStr.substring(2));
            // Set this time into todays calendar date.
            calendar.set(Calendar.HOUR_OF_DAY, hours);
            calendar.set(Calendar.MINUTE, minutes);
            // Check the result.
            System.out.println("timeStamp = " + df.format(calendar.getTime()));

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:41 PM
  3. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 AM
  4. DataObject with the time given by me
    By garinapavan in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 06:33 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
  •