org.mtzky.date
クラス DateHelper

java.lang.Object
  上位を拡張 org.mtzky.date.DateHelper
すべての実装されたインタフェース:
Cloneable, Comparable<DateHelper>
直系の既知のサブクラス:
ThreadLocalDateHelper

public class DateHelper
extends Object
implements Comparable<DateHelper>, Cloneable

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();
 Date date = 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();
 

導入されたバージョン:
0.1.9
作成者:
mtzky
関連項目:
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
 

コンストラクタの詳細

DateHelper

public DateHelper()

Initializes time as System.currentTimeMillis().

関連項目:
DateHelper(long), setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

public DateHelper(long timeMillis)

Initializes time as timeMillis.

パラメータ:
timeMillis -
関連項目:
setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

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 fields
関連項目:
DateHelper(TimeZone, Locale, int[]), setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

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 use
args - the values for the Calendar fields
関連項目:
DateHelper(TimeZone, Locale, int[]), setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

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 data
args - the values for the Calendar fields
関連項目:
DateHelper(TimeZone, Locale, int[]), setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

public DateHelper(TimeZone timeZone,
                  Locale locale,
                  int... args)

Initializes time with the given args for the corresponding calendar fields.

  1. Calendar.YEAR
  2. Calendar.MONTH (zero-origin; use Calendar.JANUARY ... Calendar.DECEMBER)
  3. Calendar.DATE
  4. Calendar.HOUR_OF_DAY
  5. Calendar.MINUTE
  6. Calendar.SECOND
  7. Calendar.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 use
locale - the locale for the week data
args - the values for the Calendar fields
例外:
NullPointerException - if args is null
IllegalArgumentException - if args.length is eight or more
関連項目:
setFirstDayOfWeek(int)

DateHelper

public DateHelper(Date date)

Initializes time as Date.getTime().

パラメータ:
date - Date
関連項目:
setTimeZone(TimeZone), setLocale(Locale), setFirstDayOfWeek(int)

DateHelper

public DateHelper(Calendar calendar)

Initializes time as Calendar.getTimeInMillis().

パラメータ:
calendar - Calendar
関連項目:
setLocale(Locale)

DateHelper

public DateHelper(Calendar calendar,
                  Locale locale)

Initializes time as Calendar.getTimeInMillis().

パラメータ:
calendar - Calendar
locale - the locale for the week data
関連項目:
setLocale(Locale)
メソッドの詳細

add

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 method
関連項目:
Calendar.add(int, int)

roll

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 method
関連項目:
Calendar.roll(int, int)

set

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 method

truncate

public 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 method
関連項目:
Calendar.getFirstDayOfWeek()

getTimeMillis

public long getTimeMillis()
戻り値:
time in milliseconds.

getCalendar

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)

getDate

public final Date getDate()
戻り値:
Date initialized to represent the specified number of milliseconds.

getSqlDate

public final Date getSqlDate()
戻り値:
Date initialized to represent the specified number of milliseconds.

getSqlTimestamp

public final Timestamp getSqlTimestamp()
戻り値:
Timestamp initialized to represent the specified number of milliseconds.

getSqlTime

public final Time getSqlTime()
戻り値:
Time initialized to represent the specified number of milliseconds.

format

public String format()
戻り値:
formatted date string with DateFormat
関連項目:
format(int, int)

format

public String format(int dateStyle,
                     int timeStyle)
パラメータ:
dateStyle - the given date formatting style
timeStyle - the given time formatting style
戻り値:
formatted date string with DateFormat
関連項目:
DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM, DateFormat.SHORT, DateFormat.DEFAULT

format

public String format(String pattern)
パラメータ:
pattern - the pattern describing the date and time format
戻り値:
formatted date string with SimpleDateFormat

setDefaultLocale

public static void setDefaultLocale(Locale defaultLocale)
パラメータ:
defaultLocale - Locale

setDefaultTimeZone

public static void setDefaultTimeZone(TimeZone defaultTimeZone)
パラメータ:
defaultTimeZone - TimeZone

setDefaultFirstDayOfWeek

public static void setDefaultFirstDayOfWeek(int defaultFirstDayOfWeek)
パラメータ:
defaultFirstDayOfWeek - Calendar.setFirstDayOfWeek(int)

setLocale

public DateHelper setLocale(Locale locale)
パラメータ:
locale - Locale

setTimeZone

public DateHelper setTimeZone(TimeZone timeZone)
パラメータ:
timeZone - TimeZone

setFirstDayOfWeek

public DateHelper setFirstDayOfWeek(int firstDayOfWeek)
パラメータ:
firstDayOfWeek - Calendar.setFirstDayOfWeek(int)

toString

public final String toString()
オーバーライド:
クラス Object 内の toString

hashCode

public final int hashCode()
オーバーライド:
クラス Object 内の hashCode

equals

public final boolean equals(Object obj)
オーバーライド:
クラス Object 内の equals

compareTo

public final int compareTo(DateHelper dateHelper)
定義:
インタフェース Comparable<DateHelper> 内の compareTo

clone

public final DateHelper clone()
オーバーライド:
クラス Object 内の clone
戻り値:
DateHelper
関連項目:
Object.clone(), Cloneable


Copyright (C) 2010-2011 Mtzky. AllRights Reserved.