Results 1 to 3 of 3
  1. #1
    peted is offline Member
    Join Date
    Dec 2014
    Rep Power

    Default list hours between two dates.

    is there away to list all hours between two dates?

    For example if i have 12/7/2014 21:03:56 and 12/8/2014 04:40:45 I need an output, i can write to a file: (the dates are currently in String variables)

    12/7/2014 21:00
    12/7/2014 22:00
    12/7/2014 23:00
    12/8/2014 00:00
    12/8/2014 01:00
    12/8/2014 02:00
    12/8/2014 03:00
    12/8/2014 04:00

    Any suggestion how this can be achieved would be greatly appreciated.


  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: list hours between two dates.

    I would suggest you investigate the Calendar and Date classes (however, certain features of latter are deprecated). A simple algorithm would be to take starting date, round to current hour, and then keep updating hour until final time reached.

    Last edited by jim829; 12-09-2014 at 05:04 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: list hours between two dates.

    Or the java 8 time package:

    or not having access to Java 8, you might also be interested in the third party JodaTime.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 4
    Last Post: 09-08-2013, 06:59 PM
  2. Integer Dates to String Dates Problem
    By HelpingIsCaring in forum New To Java
    Replies: 32
    Last Post: 08-23-2013, 01:29 AM
  3. negetive hours when subtracting dates
    By emyk in forum Advanced Java
    Replies: 1
    Last Post: 04-21-2011, 02:50 AM
  4. getting hours and minutes
    By silversurfer2in in forum New To Java
    Replies: 5
    Last Post: 02-17-2010, 08:35 AM

Tags for this Thread

Posting Permissions

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