Results 1 to 4 of 4
  1. #1
    osval is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default help with dates and time

    I have a program where I expect the user to enter two values, a date and time in these formats:
    Java Code:
    7/28/2008
    22:30
    6:45
    if I receive this information as a string, what the best way to parse out the day, month, year and hour, minute values?

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

    Default

    Java Code:
    // 7/28/2008
    // 22:30
    String dayStr = "7/28/2008";
    String timeStr = "22:30";
    String[] dateTokens = dayStr.split("\\/");
    String[] timeTokens = timeStr.split("\\:");
    System.out.println("day     = " + dateTokens[0]);
    System.out.println("month   = " + dateTokens[1]);
    System.out.println("year    = " + dateTokens[2]);
    System.out.println("hours   = " + timeTokens[0]);
    System.out.println("minutes = " + timeTokens[1]);

  3. #3
    osval is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default

    thank you hard

  4. #4
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Default

    StringTokenizer class can also be used, which would be easier
    Thanks & Regards, G.Rajasekhar

Similar Threads

  1. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 07:05 AM
  2. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:06 AM
  3. Comparing dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:02 AM
  4. Inbetween Dates
    By Rageagainst20 in forum New To Java
    Replies: 4
    Last Post: 12-19-2007, 05:24 AM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 05:37 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
  •