Java Newbie Calendar Class Questions -


need understanding below test code. not understand "11" , "12" represent in calendar.set method? example "opencal.set(11, openhrs).

public static void main(string[] args) {       {           int openhrs = 07;          int openmins = 30;          int closedhrs = 23;          int closedmins = 00;          calendar cal = calendar.getinstance();          calendar opencal = calendar.getinstance();          opencal.set(11, openhrs);          opencal.set(12, openmins);          calendar closecal = calendar.getinstance();          closecal.set(11, closedhrs);          closecal.set(12, closedmins);          if(opencal.before(cal) && closecal.after(cal))          {            system.out.println("the business open");           } else          {             system.out.println("the business closed");          }      }  } 

this perfect example of why should avoid magic numbers.

instead of set(11 code should set(calendar.hour_of_day.
instead of set(12 code should set(calendar.minute.

if take @ documentation of calendar class find few examples of how use set methods

  • set(calendar.month, calendar.september)
  • set(calendar.day_of_month, 30)

by looking @ source code of calendar class find many constants , values. can found @

http://docs.oracle.com/javase/8/docs/api/constant-values.html

so see


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -