Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for Date Time  RSS feed

 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a batch program. The batch program has a check as below how do I write it, any suggestions ?

Check the current system time falls between Saturday 1.00 AM and Sunday 1.00 PM.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Santhosh Jali:
I am writing a batch program. The batch program has a check as below how do I write it, any suggestions ?

Check the current system time falls between Saturday 1.00 AM and Sunday 1.00 PM.


Create a Calendar() object. Then use it's get() method to see if (DAY_OF_WEEK is Saturday and HOUR_OF_DAY >= 1) or (DAY_OF_WEEK is SUNDAY and HOUR_OF_DAY < 13).

Calendar is a class that isn't constructed with new. You have to call it's getInstance() method.

Calendar now = Calendar.getInstance();

To get values you have to use Calendar defined constants

int theHourOfDay = now.get(Calendar.HOUR_OF_DAY)
if ( now.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY )
{

}
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!