If year is non-negative:
Sakamoto algorithm implementation in C++: 0 = sunday, 1 = monday, ..., 6 = saturday.
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
int dow(int y, int m, int d) {
y -= m<3;
return (d + t[m-1] + y + y/4 - y/100 + y/400) % 7;
}
In Javascript:
// m = 1, 2, ..., 12
// result: 0 = sun, 1 = mon, ..., 6 = sat
function dayOfWeek(y, m, d) {
if (m<3) y--
m = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4][m-1]
return (d + m + y + ~~(y/4) - ~~(y/100) + ~~(y/400)) % 7
}