Results 1 to 6 of 6

Thread: DATE in JAVA

  1. #1
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Exclamation DATE in JAVA

    hi,
    my program needs to run a particular process only between say, 9 am to 5 pm every day. and if the system time is not between this, the if shud not be executed.

    how to obtain such a functioanality. I would prefer the start time and end time to be configurable , to be picked up from a properties file.

    any clues..??

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Java Code:
    Calendar calendar = GregorianCalendar.getInstance();
    System.out.println(calendar.get(Calendar.HOUR_OF_DAY));

    Also: Properties in java
    My Hobby Project: LegacyClone

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Unix or Windows (or other)? I believe that unix OS has this timer functionality built in to it, and it could possibly even start up your app each day at a certain time.

    Also, does your program need to use a java.util.Timer?

  4. #4
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Exclamation

    there are 3 threads running at the moment.. all kicked off from the same java class..
    with sleep times configured.. so once the thread.sleep() is invoked, it sleeps for the specified time..

    all three threads function the same way..

    but i need one of these threads to run between a particular duration of the day.. and rest of the time.. run/sleep.. but shud not perform the functionality that is expected out of it..

  5. #5
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Exclamation

    using windows OS.. the entire program is goin to be deployed on unix but.. is it possible to control jus one thread in UNIX..??

    the whole program as such will be running based on a particular time line..

  6. #6
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Java Code:
    public void run()
    {
       while(running)
       {
          ...
          Calendar calendar = GregorianCalendar.getInstance();
    
          int hour = calendar.get(Calendar.HOUR_OF_DAY);
          while( hour <9 || hour >= 17 )
          {
             if(!running)
                return;
             try {
                sleep(1000); //or some other time amount
             }catch(Exception e) {}
          }
          ...
       }
    }
    Last edited by mrmatt1111; 10-06-2009 at 07:17 AM.
    My Hobby Project: LegacyClone

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 02:59 PM
  2. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  3. 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
  4. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  5. Using java.sql.Date
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:32 AM

Posting Permissions

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