-1

Hey guys im trying to find some info regarding java and the calendar class. I need to write an if statement that says if it is a weekend i.e sat or sunday then do this else do this

Cheers

Thanks for the help however i don't think im implementing it correctly, nothing is being displayed now.

$(document).ready(function() {
 function recalculate() {
    var sum = 49;
    int day = Calendar.getInstance().get( Calendar.DAY_OF_WEEK );

    if ( day == Calendar.SATURDAY || day == Calendar.SUNDAY ){
    sum = 80;
    }
    $("input[type=checkbox]:checked").each(function() {
        sum =  parseInt($(this).attr("rel"));

    });

    $("#output").html(sum);
 }

 $("input[type=checkbox]").change(function() {
    recalculate();
 });

});
user unknown
  • 35,537
  • 11
  • 75
  • 121
Simon
  • 121
  • 1
  • 2
  • 8

4 Answers4

1

It's all in here: http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html

int day = Calendar.getInstance().get( Calendar.DAY_OF_WEEK );

if ( day == Calendar.SATURDAY || day == Calendar.SUNDAY ){
   // fun fun fun fun fun
}
Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48
1
if(cal.get(Calendar.DAY_OF_WEEK)== Calendar.SATURDAY ||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
    //hurray..weekend..!
}else{

}

See Also

jmj
  • 237,923
  • 42
  • 401
  • 438
0
Calendar cld = Calendar.getInstance();
if (cld.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
// it's saturday
}
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

@Simone The code you have there does not look anything like Java - infact, it's more like JavaScript in JQuery format. Anyway, @Matthew and @Jigar have provided you with sample code.

If that does not help, them make sure to tag your question as Javascript next time so that people with that experience can help answer your question.

Good luck

Helen Neely
  • 4,666
  • 8
  • 40
  • 64