We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
day of the week (Read 474 times)
day of the week
Jan 30th, 2009, 11:24pm
 
hello,
i'm working on how to tell what day of the week it is (sun-sat) in processing. i tried looking for tutorials, but only found hacks using java. this is part of my code below. any help is appreciated. thanks!


void daytext(){
 wk = (wk + 1) % 7; //What does this do?
 
  if (wk == 0) {
  su();
  }
  else if (wk == 1){
  mo();
  }
  else if (wk == 2){
  tu();
  }
  else if (wk == 3){
  we();
  }
  else if (wk == 4){
  th();
  }
  else if (wk == 5){
  fr();
  }
  else if (wk == 6) {
  sa();
  }
Re: day of the week
Reply #1 - Feb 1st, 2009, 5:29am
 
void daytext(){
 wk = (wk + 1) % 7; //What does this do?

the above code does this:
"the remainder of (wk + 1) divided by 7 equals wk"


here's the code to get day of week, tweak it to suit your needs:



GregorianCalendar gcal = new GregorianCalendar();

void setup(){
size(50,50);
frameRate(30);
}

void draw(){
background(0);

int week = gcal.getActualMaximum(Calendar.DAY_OF_WEEK);

   println("Day of week: " + week);

   int first = gcal.getFirstDayOfWeek() ;

   switch(first){
     case 1:
       println("Sunday");
       break;
     case 2:
       println("Monday");
     break;
     case 3:
       println("Tuesday");
       break;
     case 4:
      println("Wednesday");
     break;
     case 5:
       println("Thrusday");
     break;      
     case 6:
       println("Friday");
     break;
     case 7:
       println("Saturday");
     break;  
 }
}
Re: day of the week
Reply #2 - Feb 1st, 2009, 6:10am
 
thanks so much for your help! take care.
Page Index Toggle Pages: 1