|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectorg.mtzky.date.DateHelper
public class DateHelper
DateHelper is utilities for the Calendar and Date object.
Setter methods are NOT destructive, returns another instance, and can chain methods.
final DateHelper dateHelper = new DateHelper();Datedate = dateHelper .add(Calendar.YEAR, -2) .add(Calendar.MONTH, 6) .set(Calendar.DATE, 25) .set(Calendar.HOUR_OF_DAY, 10) .truncate(Calendar.HOUR_OF_DAY) .getDate();
setDefaultTimeZone(TimeZone),
setDefaultLocale(Locale),
setDefaultFirstDayOfWeek(int)| コンストラクタの概要 | |
|---|---|
DateHelper()
Initializes time as System.currentTimeMillis(). |
|
DateHelper(Calendar calendar)
Initializes time as Calendar.getTimeInMillis(). |
|
DateHelper(Calendar calendar,
Locale locale)
Initializes time as Calendar.getTimeInMillis(). |
|
DateHelper(Date date)
Initializes time as Date.getTime(). |
|
DateHelper(int... args)
Initializes time with the given args for the corresponding
calendar fields. |
|
DateHelper(Locale locale,
int... args)
Initializes time with the given args for the corresponding
calendar fields. |
|
DateHelper(long timeMillis)
Initializes time as timeMillis. |
|
DateHelper(TimeZone timeZone,
int... args)
Initializes time with the given args for the corresponding
calendar fields. |
|
DateHelper(TimeZone timeZone,
Locale locale,
int... args)
Initializes time with the given args for the corresponding
calendar fields. |
|
| メソッドの概要 | |
|---|---|
DateHelper |
add(int field,
int amount)
Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules. |
DateHelper |
clone()
|
int |
compareTo(DateHelper dateHelper)
|
boolean |
equals(Object obj)
|
String |
format()
|
String |
format(int dateStyle,
int timeStyle)
|
String |
format(String pattern)
|
Calendar |
getCalendar()
Gets a calendar initialized to represent the specified number of milliseconds, using the specified
time zone, locale, and first day of week. |
Date |
getDate()
|
Date |
getSqlDate()
|
Time |
getSqlTime()
|
Timestamp |
getSqlTimestamp()
|
long |
getTimeMillis()
|
int |
hashCode()
|
DateHelper |
roll(int field,
int amount)
Adds the specified (signed) amount to the specified calendar field without changing larger fields. |
DateHelper |
set(int field,
int value)
Sets the given calendar field to the given value. |
static void |
setDefaultFirstDayOfWeek(int defaultFirstDayOfWeek)
|
static void |
setDefaultLocale(Locale defaultLocale)
|
static void |
setDefaultTimeZone(TimeZone defaultTimeZone)
|
DateHelper |
setFirstDayOfWeek(int firstDayOfWeek)
|
DateHelper |
setLocale(Locale locale)
|
DateHelper |
setTimeZone(TimeZone timeZone)
|
String |
toString()
|
DateHelper |
truncate(int field)
Truncates a time leaving the specified field. |
| クラス java.lang.Object から継承されたメソッド |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| コンストラクタの詳細 |
|---|
public DateHelper()
Initializes time as System.currentTimeMillis().
DateHelper(long),
setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)public DateHelper(long timeMillis)
Initializes time as timeMillis.
timeMillis - setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)public DateHelper(int... args)
Initializes time with the given args for the corresponding
calendar fields. For more information, please see
DateHelper(TimeZone, Locale, int[]).
args - the values for the Calendar fieldsDateHelper(TimeZone, Locale, int[]),
setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)
public DateHelper(TimeZone timeZone,
int... args)
Initializes time with the given args for the corresponding
calendar fields. For more information, please see
DateHelper(TimeZone, Locale, int[]).
timeZone - the time zone to useargs - the values for the Calendar fieldsDateHelper(TimeZone, Locale, int[]),
setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)
public DateHelper(Locale locale,
int... args)
Initializes time with the given args for the corresponding
calendar fields. For more information, please see
DateHelper(TimeZone, Locale, int[]).
locale - the locale for the week dataargs - the values for the Calendar fieldsDateHelper(TimeZone, Locale, int[]),
setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)
public DateHelper(TimeZone timeZone,
Locale locale,
int... args)
Initializes time with the given args for the corresponding
calendar fields.
Calendar.YEARCalendar.MONTH (zero-origin; use Calendar.JANUARY ...
Calendar.DECEMBER)Calendar.DATECalendar.HOUR_OF_DAYCalendar.MINUTECalendar.SECONDCalendar.MILLISECOND
NOTE: This method execute setTimeInMillis(0L) before set to the
corresponding calendar field. If you pass locale ja_JP_JP,
JapaneseImperialCalendar is used as Calendar, and
initialized that ERA is Showa (3). Showa 45
is A.D. 1970.
timeZone - the time zone to uselocale - the locale for the week dataargs - the values for the Calendar fields
NullPointerException - if args is null
IllegalArgumentException - if args.length is eight or moresetFirstDayOfWeek(int)public DateHelper(Date date)
Initializes time as Date.getTime().
date - DatesetTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)public DateHelper(Calendar calendar)
Initializes time as Calendar.getTimeInMillis().
calendar - CalendarsetLocale(Locale)
public DateHelper(Calendar calendar,
Locale locale)
Initializes time as Calendar.getTimeInMillis().
calendar - Calendarlocale - the locale for the week datasetLocale(Locale)| メソッドの詳細 |
|---|
public final DateHelper add(int field,
int amount)
Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.
field - the calendar field.amount - the amount of date or time to be added to the field.
DateHelper to chain methodCalendar.add(int, int)
public final DateHelper roll(int field,
int amount)
Adds the specified (signed) amount to the specified calendar field without changing larger fields. A negative amount means to roll down.
field - the given calendar field.amount - the signed amount to add to the calendar field.
DateHelper to chain methodCalendar.roll(int, int)
public final DateHelper set(int field,
int value)
Sets the given calendar field to the given value.
field - the given calendar field.value - the value to be set for the given calendar field.
DateHelper to chain methodpublic final DateHelper truncate(int field)
Truncates a time leaving the specified field.
| Specified Field | Truncated Date |
|---|---|
| Original Date | 2011-12-13 14:15:16.017 |
Calendar.ERA |
0001-01-01 00:00:00.000 |
Calendar.YEAR |
2011-01-01 00:00:00.000 |
Calendar.MONTH |
2011-12-01 00:00:00.000 |
Calendar.WEEK_OF_YEAR |
2011-12-11 00:00:00.000 |
Calendar.WEEK_OF_MONTH |
|
Calendar.DATE |
2011-12-13 00:00:00.000 |
Calendar.DAY_OF_MONTH |
|
Calendar.DAY_OF_YEAR |
|
Calendar.DAY_OF_WEEK |
|
Calendar.DAY_OF_WEEK_IN_MONTH |
|
Calendar.AM_PM |
2011-12-13 12:00:00.000 |
Calendar.HOUR |
|
Calendar.HOUR_OF_DAY |
2011-12-13 14:00:00.000 |
Calendar.MINUTE |
2011-12-13 14:15:00.000 |
Calendar.SECOND |
2011-12-13 14:15:16.000 |
Calendar.MILLISECOND |
2011-12-13 14:15:16.017 |
NOTE: Takes Calendar.getFirstDayOfWeek() as a truncated time
leaving Calendar.WEEK_OF_YEAR/Calendar.WEEK_OF_MONTH.
field - the calendar field.
DateHelper to chain methodCalendar.getFirstDayOfWeek()public long getTimeMillis()
public final Calendar getCalendar()
Gets a calendar initialized to represent the specified number of milliseconds, using the specified
time zone, locale, and first day of week.
Calendar initialized to represent the specified number of
milliseconds.getTimeMillis(),
setTimeZone(TimeZone),
setLocale(Locale),
setFirstDayOfWeek(int)public final Date getDate()
Date initialized to represent the specified
number of
milliseconds.public final Date getSqlDate()
Date initialized to represent the specified
number of milliseconds.public final Timestamp getSqlTimestamp()
Timestamp initialized to represent the specified
number of milliseconds.public final Time getSqlTime()
Time initialized to represent the specified
number of milliseconds.public String format()
date string with DateFormatformat(int, int)
public String format(int dateStyle,
int timeStyle)
dateStyle - the given date formatting styletimeStyle - the given time formatting style
date string with DateFormatDateFormat.FULL,
DateFormat.LONG,
DateFormat.MEDIUM,
DateFormat.SHORT,
DateFormat.DEFAULTpublic String format(String pattern)
pattern - the pattern describing the date and time format
date string with
SimpleDateFormatpublic static void setDefaultLocale(Locale defaultLocale)
defaultLocale - Localepublic static void setDefaultTimeZone(TimeZone defaultTimeZone)
defaultTimeZone - TimeZonepublic static void setDefaultFirstDayOfWeek(int defaultFirstDayOfWeek)
defaultFirstDayOfWeek - Calendar.setFirstDayOfWeek(int)public DateHelper setLocale(Locale locale)
locale - Localepublic DateHelper setTimeZone(TimeZone timeZone)
timeZone - TimeZonepublic DateHelper setFirstDayOfWeek(int firstDayOfWeek)
firstDayOfWeek - Calendar.setFirstDayOfWeek(int)public final String toString()
Object 内の toStringpublic final int hashCode()
Object 内の hashCodepublic final boolean equals(Object obj)
Object 内の equalspublic final int compareTo(DateHelper dateHelper)
Comparable<DateHelper> 内の compareTopublic final DateHelper clone()
Object 内の cloneDateHelperObject.clone(),
Cloneable
|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||