Calendar Util : Calendar Date « Development Class « Java






Calendar Util

        

import java.util.Calendar;
import java.util.logging.Logger;

/**
 * {@link java.util.Calendar} utilities
 * 
 * @author Kazuhiro Sera
 */
public final class CalendarUtil {
  public static Calendar testData;

  public static Calendar getCurrentTime() {
    if (testData != null) {
      Calendar result = deepCopy(testData);
      testData = null;
      return result;
    } else {
      return Calendar.getInstance();
    }
  }

  public static Calendar getCurrentTruncDate() {
    return dateTrunc(getCurrentTime());
  }

  public static Integer getYear(Calendar calendar) {
    Integer year = calendar.get(Calendar.YEAR);
    return year;
  }

  public static Integer getMonth(Calendar calendar) {
    Integer month = calendar.get(Calendar.MONTH) + 1;
    return month;
  }

  public static Integer getDay(Calendar calendar) {
    Integer day = calendar.get(Calendar.DATE);
    return day;
  }

  public static Integer getDayOfWeekNumber(Calendar cal) {
    return cal.get(Calendar.DAY_OF_WEEK);
  }

  public static Integer get24Hour(Calendar calendar) {
    Integer hour = calendar.get(Calendar.HOUR_OF_DAY);
    return hour;
  }

  public static Integer getMinute(Calendar calendar) {
    Integer minute = calendar.get(Calendar.MINUTE);
    return minute;
  }

  public static Integer getSecond(Calendar calendar) {
    Integer second = calendar.get(Calendar.SECOND);
    return second;
  }

  public static Integer getMillisecond(Calendar calendar) {
    Integer millisecond = calendar.get(Calendar.MILLISECOND);
    return millisecond;
  }

  public static Calendar getCalendar(String yyyy, String mm, String dd) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, Integer.valueOf(yyyy));
    cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1);
    cal.set(Calendar.DATE, Integer.valueOf(dd));
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
  }

  public static Calendar getCalendar(int yyyy, int mm, int dd) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, yyyy);
    cal.set(Calendar.MONTH, mm - 1);
    cal.set(Calendar.DATE, dd);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
  }

  public static Calendar getCalendar(String yyyy, String mm, String dd,
      String hh, String mi, String ss) {
    Calendar cal = getCalendar(yyyy, mm, dd);
    cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(hh));
    cal.set(Calendar.MINUTE, Integer.valueOf(mi));
    cal.set(Calendar.SECOND, Integer.valueOf(ss));
    return cal;
  }

  public static Calendar getCalendar(int yyyy, int mm, int dd, int hh,
      int mi, int ss) {
    Calendar cal = getCalendar(yyyy, mm, dd);
    cal.set(Calendar.HOUR_OF_DAY, hh);
    cal.set(Calendar.MINUTE, mi);
    cal.set(Calendar.SECOND, ss);
    return cal;
  }

  public static Calendar dateTrunc(Calendar calendar) {
    if (calendar == null) {
      return null;
    }
    Calendar date = (Calendar) calendar.clone();
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;
  }

  public static boolean isFirstAfterSecond(Calendar first, Calendar second) {
    long firstValue = first.getTimeInMillis();
    long secondValue = second.getTimeInMillis();
    return (firstValue > secondValue) ? true : false;
  }

  public static Calendar deepCopy(Calendar src) {
    Calendar dest = Calendar.getInstance();
    dest.setTimeInMillis(src.getTimeInMillis());
    return dest;
  }

  public static Calendar addYears(Calendar src, int years) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.YEAR, years);
    return dest;
  }

  public static Calendar addMonths(Calendar src, int months) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.MONTH, months);
    return dest;
  }

  public static Calendar addDays(Calendar src, int days) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.DATE, days);
    return dest;
  }

  public static Calendar addHours(Calendar src, int hours) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.HOUR_OF_DAY, hours);
    return dest;
  }

  public static Calendar addMinutes(Calendar src, int minutes) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.MINUTE, minutes);
    return dest;
  }

  public static Calendar addSeconds(Calendar src, int seconds) {
    Calendar dest = deepCopy(src);
    dest.add(Calendar.SECOND, seconds);
    return dest;
  }

  public static Calendar getCalendar(long timeInMillis) {
    Calendar dest = Calendar.getInstance();
    dest.setTimeInMillis(timeInMillis);
    return dest;
  }

  public static String toYYYYMMDDHHMISS(Calendar calendar) {
    return String.format("%04d", getYear(calendar))
        + String.format("%02d", getMonth(calendar))
        + String.format("%02d", getDay(calendar))
        + String.format("%02d", get24Hour(calendar))
        + String.format("%02d", getMinute(calendar))
        + String.format("%02d", getSecond(calendar));
  }

}
------
package net.seratch.taskun.util;

import java.util.Calendar;

import junit.framework.TestCase;

public class CalendarUtilTest extends TestCase {

  public void test_getYear_A$Calendar() throws Exception {
    Integer expected = 2009;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.YEAR, expected);
    Integer actual = CalendarUtil.getYear(arg0);
    assertEquals(expected, actual);
  }

  public void test_getYear_A$Calendar_1899() throws Exception {
    Integer expected = 1899;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.YEAR, expected);
    Integer actual = CalendarUtil.getYear(arg0);
    assertEquals(expected, actual);
  }

  public void test_getYear_A$Calendar_1900() throws Exception {
    Integer expected = 1900;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.YEAR, expected);
    Integer actual = CalendarUtil.getYear(arg0);
    assertEquals(expected, actual);
  }

  public void test_getYear_A$Calendar_2037() throws Exception {
    Integer expected = 2037;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.YEAR, expected);
    Integer actual = CalendarUtil.getYear(arg0);
    assertEquals(expected, actual);
  }

  public void test_getYear_A$Calendar_2038() throws Exception {
    Integer expected = 2038;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.YEAR, expected);
    Integer actual = CalendarUtil.getYear(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMonth_A$Calendar() throws Exception {
    Integer expected = 10;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MONTH, expected - 1);
    Integer actual = CalendarUtil.getMonth(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMonth_A$Calendar_jun0() throws Exception {
    Integer expected = 1;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MONTH, 0);
    Integer actual = CalendarUtil.getMonth(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMonth_A$Calendar_jun12() throws Exception {
    Integer expected = 1;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MONTH, 12);
    Integer actual = CalendarUtil.getMonth(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMonth_A$Calendar_dec() throws Exception {
    Integer expected = 12;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MONTH, 11);
    Integer actual = CalendarUtil.getMonth(arg0);
    assertEquals(expected, actual);
  }

  public void test_getDay_A$Calendar() throws Exception {
    Integer expected = 10;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.DATE, expected);
    Integer actual = CalendarUtil.getDay(arg0);
    assertEquals(expected, actual);
  }

  public void test_get24Hour_A$Calendar() throws Exception {
    Integer expected = 23;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.HOUR_OF_DAY, expected);
    Integer actual = CalendarUtil.get24Hour(arg0);
    assertEquals(expected, actual);
  }

  public void test_get24Hour_A$Calendar_0() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.HOUR_OF_DAY, expected);
    Integer actual = CalendarUtil.get24Hour(arg0);
    assertEquals(expected, actual);
  }

  public void test_get24Hour_A$Calendar_24() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.HOUR_OF_DAY, 24);
    Integer actual = CalendarUtil.get24Hour(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMinute_A$Calendar() throws Exception {
    Integer expected = 59;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MINUTE, expected);
    Integer actual = CalendarUtil.getMinute(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMinute_A$Calendar_60() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MINUTE, 60);
    Integer actual = CalendarUtil.getMinute(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMinute_A$Calendar_0() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MINUTE, expected);
    Integer actual = CalendarUtil.getMinute(arg0);
    assertEquals(expected, actual);
  }

  public void test_getSecond_A$Calendar() throws Exception {
    Integer expected = 33;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.SECOND, expected);
    Integer actual = CalendarUtil.getSecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getSecond_A$Calendar_60() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.SECOND, 60);
    Integer actual = CalendarUtil.getSecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getSecond_A$Calendar_0() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.SECOND, expected);
    Integer actual = CalendarUtil.getSecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getCalendar_A$String$String$String() throws Exception {
    long expected = 1262185200000L;
    String arg0 = "2009";
    String arg1 = "12";
    String arg2 = "31";
    Calendar actual = CalendarUtil.getCalendar(arg0, arg1, arg2);
    assertEquals(expected, actual.getTimeInMillis());
  }

  public void test_getCalendar_A$String$String$String$String$String$String()
      throws Exception {
    long expected = 1262271599000L;
    String arg0 = "2009";
    String arg1 = "12";
    String arg2 = "31";
    String arg3 = "23";
    String arg4 = "59";
    String arg5 = "59";
    Calendar actual = CalendarUtil.getCalendar(arg0, arg1, arg2, arg3,
        arg4, arg5);
    assertEquals(expected, actual.getTimeInMillis());
  }

  public void test_dateTrunc_A$Calendar() throws Exception {
    Calendar today = CalendarUtil.dateTrunc(Calendar.getInstance());
    assertEquals(0, today.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, today.get(Calendar.MINUTE));
    assertEquals(0, today.get(Calendar.SECOND));
    assertEquals(0, today.get(Calendar.MILLISECOND));
  }

  public void test_getCurrentTime_A$() throws Exception {
    Calendar actual = CalendarUtil.getCurrentTime();
    assertNotNull(actual);
  }

  public void test_getCurrentTime_A$_testData() throws Exception {
    CalendarUtil.testData = Calendar.getInstance();
    Calendar actual = CalendarUtil.getCurrentTime();
    assertNotNull(actual);
    assertNull(CalendarUtil.testData);
  }

  public void test_getCurrentTruncDate_A$() throws Exception {
    Calendar actual = CalendarUtil.getCurrentTruncDate();
    assertEquals(0, actual.get(Calendar.HOUR));
    assertEquals(0, actual.get(Calendar.MINUTE));
    assertEquals(0, actual.get(Calendar.SECOND));
    assertEquals(0, actual.get(Calendar.MILLISECOND));
  }

  public void test_isFirstAfterSecond_A$Calendar$Calendar_true()
      throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    Calendar arg1 = CalendarUtil.getCalendar("2010", "2", "28");
    // when
    boolean actual = CalendarUtil.isFirstAfterSecond(arg0, arg1);
    // then
    boolean expected = true;
    assertEquals(expected, actual);
  }

  public void test_isFirstAfterSecond_A$Calendar$Calendar_false()
      throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    Calendar arg1 = CalendarUtil.getCalendar("2010", "2", "28");
    // when
    boolean actual2 = CalendarUtil.isFirstAfterSecond(arg1, arg0);
    // then
    boolean expected2 = false;
    assertEquals(expected2, actual2);
  }

  public void test_isFirstAfterSecond_A$Calendar$Calendar_same()
      throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    // when
    boolean actual3 = CalendarUtil.isFirstAfterSecond(arg0, arg0);
    // then
    boolean expected3 = false;
    assertEquals(expected3, actual3);
  }

  public void test_deepCopy_A$Calendar() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    // when
    Calendar actual = CalendarUtil.deepCopy(arg0);
    // then
    actual.add(Calendar.SECOND, 1);
    assertNotSame(arg0, actual);
    assertTrue(CalendarUtil.isFirstAfterSecond(actual, arg0));
  }

  public void test_addYears_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    // when
    Calendar actual = CalendarUtil.addYears(arg0, 1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 2011, (int) CalendarUtil.getYear(actual));
  }

  public void test_addYears_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "3", "1");
    // when
    Calendar actual = CalendarUtil.addYears(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 2009, (int) CalendarUtil.getYear(actual));
  }

  public void test_addMonths_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1");
    // when
    Calendar actual = CalendarUtil.addMonths(arg0, 1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 3, (int) CalendarUtil.getMonth(actual));
  }

  public void test_addMonths_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1");
    // when
    Calendar actual = CalendarUtil.addMonths(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 1, (int) CalendarUtil.getMonth(actual));
  }

  public void test_addDays_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "28");
    // when
    Calendar actual = CalendarUtil.addDays(arg0, 1);
    // then
    assertEquals((int) 3, (int) CalendarUtil.getMonth(actual));
    assertEquals((int) 1, (int) CalendarUtil.getDay(actual));
  }

  public void test_addDays_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "28");
    // when
    Calendar actual = CalendarUtil.addDays(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 27, (int) CalendarUtil.getDay(actual));
  }

  public void test_addHours_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addHours(arg0, 1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 23, (int) CalendarUtil.get24Hour(actual));
  }

  public void test_addHours_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addHours(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 21, (int) CalendarUtil.get24Hour(actual));
  }

  public void test_addMinutes_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addMinutes(arg0, 1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 24, (int) CalendarUtil.getMinute(actual));
  }

  public void test_addMinutes_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addMinutes(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 22, (int) CalendarUtil.getMinute(actual));
  }

  public void test_addSeconds_A$Calendar$int_plus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addSeconds(arg0, 1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 35, (int) CalendarUtil.getSecond(actual));
  }

  public void test_addSeconds_A$Calendar$int_minus() throws Exception {
    // given
    Calendar arg0 = CalendarUtil.getCalendar("2010", "2", "1", "22", "23",
        "34");
    // when
    Calendar actual = CalendarUtil.addSeconds(arg0, -1);
    // then
    assertNotSame(arg0.getTimeInMillis(), actual.getTimeInMillis());
    assertEquals((int) 33, (int) CalendarUtil.getSecond(actual));
  }

  public void test_getMillisecond_A$Calendar() throws Exception {
    Integer expected = 234;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MILLISECOND, expected);
    Integer actual = CalendarUtil.getMillisecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMillisecond_A$Calendar_999() throws Exception {
    Integer expected = 999;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MILLISECOND, expected);
    Integer actual = CalendarUtil.getMillisecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getMillisecond_A$Calendar_1000() throws Exception {
    Integer expected = 0;
    Calendar arg0 = Calendar.getInstance();
    arg0.set(Calendar.MILLISECOND, 1000);
    Integer actual = CalendarUtil.getMillisecond(arg0);
    assertEquals(expected, actual);
  }

  public void test_getCalendar_A$int$int$int() throws Exception {
    Calendar actual = CalendarUtil.getCalendar(2000, 2, 3);
    assertTrue(2000 == actual.get(Calendar.YEAR));
    assertTrue(1 == actual.get(Calendar.MONTH));
    assertTrue(3 == actual.get(Calendar.DATE));
  }

  public void test_getCalendar_A$int$int$int$int$int$int() throws Exception {
    Calendar actual = CalendarUtil.getCalendar(2000, 2, 3, 4, 5, 6);
    assertTrue(2000 == actual.get(Calendar.YEAR));
    assertTrue(1 == actual.get(Calendar.MONTH));
    assertTrue(3 == actual.get(Calendar.DATE));
    assertTrue(4 == actual.get(Calendar.HOUR));
    assertTrue(5 == actual.get(Calendar.MINUTE));
    assertTrue(6 == actual.get(Calendar.SECOND));
  }

  public void test_getDayOfWeekNumber_A$Calendar() throws Exception {
    assertEquals((int) 1,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "18")));
    assertEquals((int) 2,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "19")));
    assertEquals((int) 3,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "20")));
    assertEquals((int) 4,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "21")));
    assertEquals((int) 5,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "22")));
    assertEquals((int) 6,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "23")));
    assertEquals((int) 7,
        (int) CalendarUtil.getDayOfWeekNumber(CalendarUtil.getCalendar(
            "2010", "4", "24")));
  }

  public void test_getCalendar_A$long() throws Exception {
    long arg0 = 12345L;
    Calendar actual = CalendarUtil.getCalendar(arg0);
    assertEquals(arg0, actual.getTimeInMillis());
  }

  public void test_toYYYYMMDDHHMISS_A$Calendar() throws Exception {
    Calendar arg0 = CalendarUtil.getCalendar("2010", "02", "3", "1", "2",
        "3");
    String actual = CalendarUtil.toYYYYMMDDHHMISS(arg0);
    String expected = "20100203010203";
    assertEquals(expected, actual);
  }

}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Create a Date object using the Calendar class
2.When does the UNIX date get into troubleWhen does the UNIX date get into trouble
3.Trivial class to show use of Date and Calendar objectsTrivial class to show use of Date and Calendar objects
4.Convert longs (time_t in UNIX terminology) to seconds
5.Show use of Calendar objectsShow use of Calendar objects
6.How quickly can you press return
7.Easter - compute the day on which Easter fallsEaster - compute the day on which Easter falls
8.Show use of Calendar get() method with various parameters
9.TimeComputation for processing sqrt and Input and Output operations.
10.Bean to display a month calendar in a JPanelBean to display a month calendar in a JPanel
11.Show some date uses 1
12.Show dates before 1970
13.Compare Dates
14.Compare File Dates
15.If a date is after another date
16.If a date is before another date
17.Compute days between 2 dates
18.Show some calendar calculations
19.The best way to format a date/time is to use
20.Create SimpleDateFormats from a string read from a file
21.DateCalAdd -- compute the difference between two dates
22.Show some date uses
23.Calendar DemoCalendar Demo
24.DateDiff -- compute the difference between two dates
25.DateAdd -- compute the difference between two dates
26.Increment and Decrement a Date Using the Calendar Class
27.Increment and Decrement Months Using the Calendar Class
28.Add or subtract days to current date using Java Calendar
29.Subtract days from current date using Calendar.add method
30.Add hours to current date using Calendar.add method
31.Subtract hours from current date using Calendar.add method
32.Add minutes to current date using Calendar.add method
33.Subtract minutes from current date using Calendar.add method
34.Add months to current date using Calendar.add method
35.Subtract months from current date using Calendar.add method
36.Add seconds to current date using Calendar.add method
37.Subtract seconds from current time using Calendar.add method
38.Add week to current date using Calendar.add method
39.Add hours, minutes or seconds to a date
40.Subtract week from current date
41.Add year to current date using Calendar.add method
42.Add 10 months to the calendar
43.Subtract 1 year from the calendar
44.Subtract year from current date
45.Calendar adjust date automatically
46.Display Day of Week using Java Calendar
47.Display Month of year using Java Calendar
48.Display full date time
49.Get a List of Month Names
50.Get current date, year and month
51.Get Week of month and year using Java Calendar
52.Get the number of days in that month
53.Get the current month name
54.Get day, month, year value from the current date
55.Convert day of the year to date
56.Pass the year information to the calendar object
57.Get the last date of a month
58.Convert day of year to day of month
59.Determine the day of the week
60.Set with GregorianCalendar.YEAR, MONTH and DATE
61.Determine if an hour is between an interval
62.Parse a String to obtain a Date/GregorianCalendar object
63.Try month in a leap year
64.Determining If a Year Is a Leap Year
65.Determining the Day-of-Week for a Particular Date
66.Subtract 30 days from the calendar
67.Date and time with month
68.Date and time with day and month fully spelled-out
69.Formatting the Time Using a Custom Format
70.Convert string date to long value
71.Display date with a short day and month name
72.Convert Date to String
73.Validate a date Using DateFormat
74.Get the day name
75.Use the SimpleDateFormat from the java.text package
76.Formatting date with full day and month name and show time up to milliseconds with AM/PM
77.Getting the Current Time
78.Output current time: %tc
79.Swing: Date Time EditorSwing: Date Time Editor
80.Get day of week
81.Convert milliseconds value to date
82.Calculate the age
83.Format a duration in ms into a string as "Days,Hours,minutes and seconds"
84.Formatting Symbols for SimpleDateFormat
85.Express a duration in term of HH:MM:SS
86.Match DateMatch Date
87.Checks if two calendar objects represent the same local time.
88.Checks if two date objects are on the same day ignoring time
89.Checks if two date objects represent the same instant in time
90.Calendar Comparator
91.Calendar To String
92.Formatter that caches formatted date information
93.Date Format Cache.
94.Date and time formatting utilities and constants.
95.Formatting dates into Strings.
96.Monitored GregorianCalendar
97.RFC date format
98.Utilities for java.util.Date
99.Calendar operations