/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.8b-b-18UqY5/rev.11 * * authors: * GoToLoop * * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * FullDate Class (v1.05) * by GoToLoop (2014/Mar) * * Forum.Processing.org/two/discussion/3350/ * getting-the-day-of-the-week-without-calendar * * Studio.ProcessingTogether.com/sp/pad/export/ro.9to4yV59zus7B */ import java.util.Date; static final class FullDate { static int s, m, h; static int d, o, y; static int w; static char wc; static String wn, mn; static String inf; static final char[] weekChars = { 'N', 'M', 'T', 'W', 'H', 'F', 'S' }; static final String[] weekNames = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; static final String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; static final void refresh() { final Date present = new Date(); s = present.getSeconds(); m = present.getMinutes(); h = present.getHours(); w = present.getDay(); d = present.getDate(); o = present.getMonth(); y = present.getYear() + 1900; wc = weekChars[w]; wn = weekNames[w]; mn = monthNames[o]; inf = present.toString(); } static final int dow() { return dow(d, o, y); } // Wikipedia.org/wiki/Zeller's_congruence static final int dow(int d, int o, int y) { if (o < 2) { o += 12; y--; } return ( d + (int) ((o + 2)*2.6) + y + (y>>2) + (y/100 | 0)*6 + ~~(y/400) + 6 ) % 7; } } void setup() { FullDate.refresh(); println(FullDate.inf); println(FullDate.y + "\t" + FullDate.mn); println(str(FullDate.wc) + " - " + FullDate.dow() + "\t" + FullDate.wn); exit(); }