View Javadoc
1 /* 2 * Copyright �, Aegeus Technology Limited. 3 * All rights reserved. 4 */ 5 package jsdsi.util; 6 7 import java.util.Calendar; 8 import java.util.Date; 9 10 11 /*** 12 * Static utility class for java.util.Dates. 13 * 14 * @author Sean Radford 15 * @version $Revision: 1.2 $ $Date: 2004/05/07 13:17:39 $ 16 */ 17 public class DateUtil { 18 19 private DateUtil() { 20 // 21 } 22 23 /*** 24 * Returns a new <code>java.util.Date</code> set to 'now' except that the milliseconds are zero 25 * 26 * @return the date 27 */ 28 public static Date newDate() { 29 Calendar c = Calendar.getInstance(); 30 c.set(Calendar.MILLISECOND, 0); 31 return c.getTime(); 32 } 33 34 /*** 35 * Returns a zero-millisecond <code>java.util.Date</code> set to 'now' but with the YEAR modified by yearChange 36 * 37 * @param yearChange The value to change the year by 38 * @return the date 39 */ 40 public static Date newDate(int yearChange) { 41 Calendar c = Calendar.getInstance(); 42 c.set(Calendar.MILLISECOND, 0); 43 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 44 return c.getTime(); 45 } 46 47 /*** 48 * Returns a zero-millisecond <code>java.util.Date</code> set to 'now' but with the YEAR modified by yearChange 49 * and the MONTH modified by monthChange 50 * 51 * @param yearChange 52 * @param monthChange 53 * @return the date 54 */ 55 public static Date newDate(int yearChange, int monthChange) { 56 Calendar c = Calendar.getInstance(); 57 c.set(Calendar.MILLISECOND, 0); 58 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 59 c.set(Calendar.MONTH, c.get(Calendar.MONTH) + monthChange); 60 return c.getTime(); 61 } 62 63 /*** 64 * Returns a zero-millisecond <code>java.util.Date</code> set to 'now' but with the YEAR modified by yearChange, 65 * the MONTH modified by monthChange, and the DAY modified by dayChange 66 * 67 * @param yearChange 68 * @param monthChange 69 * @param dayChange 70 * @return the date 71 */ 72 public static Date newDate(int yearChange, int monthChange, int dayChange) { 73 Calendar c = Calendar.getInstance(); 74 c.set(Calendar.MILLISECOND, 0); 75 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 76 c.set(Calendar.MONTH, c.get(Calendar.MONTH) + monthChange); 77 c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + dayChange); 78 return c.getTime(); 79 } 80 81 /*** 82 * @param yearChange 83 * @param monthChange 84 * @param dayChange 85 * @param hourChange 86 * @return the date 87 */ 88 public static Date newDate(int yearChange, 89 int monthChange, int dayChange, int hourChange) { 90 Calendar c = Calendar.getInstance(); 91 c.set(Calendar.MILLISECOND, 0); 92 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 93 c.set(Calendar.MONTH, c.get(Calendar.MONTH) + monthChange); 94 c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + dayChange); 95 c.set(Calendar.HOUR, c.get(Calendar.HOUR) + hourChange); 96 return c.getTime(); 97 } 98 99 /*** 100 * @param yearChange 101 * @param monthChange 102 * @param dayChange 103 * @param hourChange 104 * @param minuteChange 105 * @return the date 106 */ 107 public static Date newDate(int yearChange, 108 int monthChange, 109 int dayChange, 110 int hourChange, int minuteChange) { 111 Calendar c = Calendar.getInstance(); 112 c.set(Calendar.MILLISECOND, 0); 113 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 114 c.set(Calendar.MONTH, c.get(Calendar.MONTH) + monthChange); 115 c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + dayChange); 116 c.set(Calendar.HOUR, c.get(Calendar.HOUR) + hourChange); 117 c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + minuteChange); 118 return c.getTime(); 119 } 120 121 /*** 122 * @param yearChange 123 * @param monthChange 124 * @param dayChange 125 * @param hourChange 126 * @param minuteChange 127 * @param secondChange 128 * @return the date 129 */ 130 public static Date newDate(int yearChange, 131 int monthChange, 132 int dayChange, 133 int hourChange, 134 int minuteChange, int secondChange) { 135 Calendar c = Calendar.getInstance(); 136 c.set(Calendar.MILLISECOND, 0); 137 c.set(Calendar.YEAR, c.get(Calendar.YEAR) + yearChange); 138 c.set(Calendar.MONTH, c.get(Calendar.MONTH) + monthChange); 139 c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + dayChange); 140 c.set(Calendar.HOUR, c.get(Calendar.HOUR) + hourChange); 141 c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + minuteChange); 142 c.set(Calendar.SECOND, c.get(Calendar.SECOND) + secondChange); 143 return c.getTime(); 144 } 145 }

This page was automatically generated by Maven