Why does Java’s Date.getYear() return 111 instead of 2011?

Those methods have been deprecated. Instead, use the Calendar class. import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public final class DateParseDemo { public static void main(String[] args){ final DateFormat df = new SimpleDateFormat(“MM/dd/yyyy”); final Calendar c = Calendar.getInstance(); try { c.setTime(df.parse(“04/12/2011”)); System.out.println(“Year = ” + c.get(Calendar.YEAR)); System.out.println(“Month = ” + (c.get(Calendar.MONTH))); System.out.println(“Day = ” … Read more

How can I use PHP to dynamically publish an ical file to be read by Google Calendar?

This should be very simple if Google Calendar does not require the *.ics-extension (which will require some URL rewriting in the server). $ical = “BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VEVENT UID:” . md5(uniqid(mt_rand(), true)) . “@yourhost.test DTSTAMP:” . gmdate(‘Ymd’).’T’. gmdate(‘His’) . “Z DTSTART:19970714T170000Z DTEND:19970715T035959Z SUMMARY:Bastille Day Party END:VEVENT END:VCALENDAR”; //set correct content-type-header header(‘Content-type: text/calendar; charset=utf-8’); header(‘Content-Disposition: … Read more

Changing Icon per Day

I assume this is for an iOS app. The answers is, you can’t. The Calendar app has access to functionality in iOS that us mere mortal developers cannot access. You may be able to pull this off with a jailbroken phone, but I’ve never tried that.

Converting a Date object to a calendar object [duplicate]

Here’s your method: public static Calendar toCalendar(Date date){ Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } Everything else you are doing is both wrong and unnecessary. BTW, Java Naming conventions suggest that method names start with a lower case letter, so it should be: dateToCalendar or toCalendar (as shown). OK, let’s milk your code, shall … Read more

What’s the best way to model recurring events in a calendar application? [closed]

I would use a ‘link’ concept for all future recurring events. They are dynamically displayed in the calendar and link back to a single reference object. When events have taken place the link is broken and the event becomes a standalone instance. If you attempt to edit a recurring event then prompt to change all … Read more

How to Convert any of the 5 Islamic (Hijri) Calendars’ Dates to any of 18 World Calendars without External Libraries or Complex Astronomical Formulas

An engineer, physicist, and mathematician where on a train rolling through the English countryside, when the engineer looked out the window, and seeing a lone black sheep on the hillside, exclaimed, “Hey, look, England’s got black sheep!” The physicist quickly admonished him, “All we can ascertain is that England has one black sheep.” Whereupon the … Read more

Sum two dates in Java

If you are using the Date object, you can just do: Date d1 = … Date d2 = … long sum = d1.getTime() + d2.getTime(); Date sumDate = new Date(sum); The code uses the .getTime() method that returns the number of milliseconds since the epoch. Needless to say the Date class has a lot of … Read more