Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default getting hours and minutes

    hi guys,

    i am working on a project in which i have to show the date , hours , minutes separately.
    Is there any way of getting this.
    I am getting the date from the database in string format and then parsing it using DateFormat parse() method

    Any suggestion will be highly appreciated

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    The reverse method for parse is format. Read about it in the API specs.

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

    Default

    Java Code:
    Date date = dateFormat.parse(aString);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int hours = calendar.get(Calendar.HOUR_OF_DAY);
    ... see Calendar api for more ...

  4. #4
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    suppose the date coming is "2010-02-17 12:18:12"

    i want to separate the date i.e 2010-02-17 hours-12, minutes-18 and seconds-2

    will the format class will work????

  5. #5
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    @hardwired

    thanx

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by silversurfer2in View Post
    suppose the date coming is "2010-02-17 12:18:12"

    i want to separate the date i.e 2010-02-17 hours-12, minutes-18 and seconds-2

    will the format class will work????
    It's a method not a class. Yes it will work and no I'm not going to write the code for you. Read the specs, try it and post if you get problems with your code.

Similar Threads

  1. MySQL connectivity (hours wasted)
    By ribbs2521 in forum New To Java
    Replies: 13
    Last Post: 10-21-2009, 07:18 AM
  2. Replies: 3
    Last Post: 08-11-2009, 12:18 AM
  3. Dynamic Refresh in JTable every 5 Minutes
    By britto_bicsjohn in forum AWT / Swing
    Replies: 3
    Last Post: 08-07-2009, 05:16 AM
  4. Simple Project 4 or 5 Hours Pay $100
    By billaaa777 in forum Jobs Offered
    Replies: 0
    Last Post: 08-30-2008, 12:45 AM
  5. How to beep every 5 minutes in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:40 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
  •