Day of the week: Difference between revisions

Content added Content deleted
(→‎{{header|UNIX Shell}}: Different machine/OS version #1)
(Added Java)
Line 4: Line 4:
'''In what years between 2008 and 2099 will the 25th of December be a Sunday?'''
'''In what years between 2008 and 2099 will the 25th of December be a Sunday?'''


Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [[http://en.wikipedia.org/wiki/Y2k#See_also y2k]] problems.
Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [[yp:Y2k#See_also y2k]] problems.


=={{header|Java}}==
<java>import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


public class Blah {
public static void main(String[] args) {
for(int i = 2008;i<=2099;i++){
GregorianCalendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
25);
if((cal.get(Calendar.DAY_OF_WEEK))==Calendar.SUNDAY){
System.out.println(new Date(cal.getTimeInMillis()));
}
}
}
}</java>
Output:
<pre>Sun Dec 25 00:00:00 CST 2011
Sun Dec 25 00:00:00 CST 2016
Sun Dec 25 00:00:00 CST 2022
Sun Dec 25 00:00:00 CST 2033
Sun Dec 25 00:00:00 CST 2039
Sun Dec 25 00:00:00 CST 2044
Sun Dec 25 00:00:00 CST 2050
Sun Dec 25 00:00:00 CST 2061
Sun Dec 25 00:00:00 CST 2067
Sun Dec 25 00:00:00 CST 2072
Sun Dec 25 00:00:00 CST 2078
Sun Dec 25 00:00:00 CST 2089
Sun Dec 25 00:00:00 CST 2095</pre>
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==