I created a program that is running daily at a certain time,

but I want this program to stop at some particular days(week ends),

I have used the below codes to set the current time,

public int GetDateNow()
 {
Calendar currentdate = Calendar.getInstance();
DateFormat dateformat = new SimpleDateFormat("HHmm");
String datenow = dateformat.format(currentdate.getTime());
int DN=Integer.parseInt(datenow);
return DN;
 }    

and the below code in the main class

while(true)
 {
      Thread.sleep(1*1000);
       if(gt.GetDateNow()==0000)
       {
       //perform action
      }
 }

Recommended Answers

All 3 Replies

Have a look at the Calendar API - there's a method that tells you the day of the week.

Ok, it is working now using

     int i= currentdate.get(Calendar.DAY_OF_WEEK);

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.