How to sanity check a date in Java

Key is df.setLenient(false);. This is more than enough for simple cases. If you are looking for a more robust (I doubt) and/or alternate libraries like joda-time then look at the answer by the user “tardate” final static String DATE_FORMAT = “dd-MM-yyyy”; public static boolean isDateValid(String date) { try { DateFormat df = new SimpleDateFormat(DATE_FORMAT); df.setLenient(false); … Read more

Implementing a non-terrestrial calendar

There are several non-Gregorian calendar classes derived from System.Globalization.Calendar within the Globalization namespace (i.e. JapaneseCalendar). You should be able to implement your own. I’d whip up a sample, but there are 16 abstract methods in the Calendar class… You might even be able to simply derive your class from GregorianCalendar and just override the GetMilliseconds(DateTime) … Read more

How to handle calendar TimeZones using Java?

public static Calendar convertToGmt(Calendar cal) { Date date = cal.getTime(); TimeZone tz = cal.getTimeZone(); log.debug(“input calendar has date [” + date + “]”); //Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT long msFromEpochGmt = date.getTime(); //gives you the current offset in ms from GMT at the current date int offsetFromUTC = tz.getOffset(msFromEpochGmt); … Read more

How do I create a link to add an entry to a calendar?

The links in Dave’s post are great. Just to put a few technical details about the google links into an answer here on SO: Google Calendar Link <a href=”http://www.google.com/calendar/event?action=TEMPLATE&text=Example%20Event&dates=20131124T010000Z/20131124T020000Z&details=Event%20Details%20Here&location=123%20Main%20St%2C%20Example%2C%20NY”>Add to gCal</a> the parameters being: action=TEMPLATE (required) text (url encoded name of the event) dates (ISO date format, startdate/enddate – must have both start and end … Read more

Calculate business days

Here’s a function from the user comments on the date() function page in the PHP manual. It’s an improvement of an earlier function in the comments that adds support for leap years. Enter the starting and ending dates, along with an array of any holidays that might be in between, and it returns the working … Read more

Month name as a string

Use this : Calendar cal=Calendar.getInstance(); SimpleDateFormat month_date = new SimpleDateFormat(“MMMM”); String month_name = month_date.format(cal.getTime()); Month name will contain the full month name,,if you want short month name use this SimpleDateFormat month_date = new SimpleDateFormat(“MMM”); String month_name = month_date.format(cal.getTime());

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)