Solved

capturing program time

Posted on 2013-11-20
3
253 Views
Last Modified: 2013-11-29
Hi guys
Is there a way in java to see what time of the day my program runs
For example my java program runs at 12Am, 7am, 6pm monday to saturday
through autosys scheduling tool.
So I need to have something like
If(java program is running at 12am){
// do something
}else if(java program is running at 7am){
//Do something else
}

What would be the best way to do this?
Any ideas would be greatly appreciated.
 Thanks.
0
Comment
Question by:royjayd
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 500 total points
ID: 39663910
Calendar cal = Calendar.getInstance() ;

int hours = cal.get(Calendar.HOUR_OF_DAY) ;

if (hours > 6 and hours < 8) {
   // It's the 7am run
}

etc.

Doug
0
 

Author Comment

by:royjayd
ID: 39664035
thanks
so just to confirm , if its running at 12 AM, the condition should be
if(hours > 23 && hours < 1), correct ?
0
 
LVL 27

Expert Comment

by:dpearson
ID: 39664295
Yes - that would be the test for midnight (within an hour).

Doug
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 76
MySQL  on Tomcat 8 71
What's wrong with this code? 4 28
What browser will run Java? 7 72
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question