<<< DateUtils demo class | Index | >>> |
Code that uses some of the DateUtils methods:
GregorianCalendar currentGC = new GregorianCalendar(); int currentYear = currentGC.get( Calendar.YEAR ); Date currentDate = DateUtils.getCurrentDate(); Date christmas = DateUtils.createDate( currentYear, Calendar.DECEMBER, 25 ); int daysToChristmas = DateUtils.daysDiff( currentDate, christmas ); DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.LONG ); String formattedDate = dateFormat.format( currentDate ); System.out.println( "Today is " + formattedDate ); System.out.println( "There are " + daysToChristmas + " days until Christmas." );
Resulting output:
Today is July 11, 2011 There are 166 days until Christmas.
<<< DateUtils demo class | Index | >>> |