DateFormat class Introduction

DateFormat is an abstract class for date/time formatting.

TypeFieldSummary
static intAM_PM_FIELDUseful constant for AM_PM field alignment.
static intDATE_FIELDUseful constant for DATE field alignment.
static intDAY_OF_WEEK_FIELDUseful constant for DAY_OF_WEEK field alignment.
static intDAY_OF_WEEK_IN_MONTH_FIELDUseful constant for DAY_OF_WEEK_IN_MONTH field alignment.
static intDAY_OF_YEAR_FIELDUseful constant for DAY_OF_YEAR field alignment.
static intERA_FIELDUseful constant for ERA field alignment.
static intHOUR_OF_DAY0_FIELDUseful constant for zero-based HOUR_OF_DAY field alignment.
static intHOUR_OF_DAY1_FIELDUseful constant for one-based HOUR_OF_DAY field alignment.
static intHOUR0_FIELDUseful constant for zero-based HOUR field alignment.
static intHOUR1_FIELDUseful constant for one-based HOUR field alignment.
static intMILLISECOND_FIELDUseful constant for MILLISECOND field alignment.
static intMINUTE_FIELDUseful constant for MINUTE field alignment.
static intMONTH_FIELDUseful constant for MONTH field alignment.
static intSECOND_FIELDUseful constant for SECOND field alignment.
static intTIMEZONE_FIELDUseful constant for TIMEZONE field alignment.
static intWEEK_OF_MONTH_FIELDUseful constant for WEEK_OF_MONTH field alignment.
static intWEEK_OF_YEAR_FIELDUseful constant for WEEK_OF_YEAR field alignment.
static intYEAR_FIELDUseful constant for YEAR field alignment.

TypeFieldSummary
static intDEFAULTConstant for default style pattern.
static intFULLConstant for full style pattern.
static intLONGConstant for long style pattern.
static intMEDIUMConstant for medium style pattern.
static intSHORTConstant for short style pattern.

Format a date

ReturnMethodSummary
Stringformat(Date date)Formats a Date into a date/time string.
StringBufferformat(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition)Overrides Format.

Create new DateFormat instance

ReturnMethodSummary
CalendargetCalendar()Gets the calendar associated with this date/time formatter.
static DateFormatgetDateInstance()Gets the date formatter with the default formatting style for the default locale.
static DateFormatgetDateInstance(int style)Gets the date formatter with the given formatting style for the default locale.
static DateFormatgetDateInstance(int style, Locale aLocale)Gets the date formatter with the given formatting style for the given locale.
static DateFormatgetDateTimeInstance()Gets the date/time formatter with the default formatting style for the default locale.
static DateFormatgetDateTimeInstance(int dateStyle, int timeStyle)Gets the date/time formatter with the given date and time formatting styles for the default locale.
static DateFormatgetDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)Gets the date/time formatter with the given formatting styles for the given locale.
static DateFormatgetInstance()Get a default date/time formatter that uses the SHORT style for both the date and the time.
NumberFormatgetNumberFormat()Gets the number formatter which this date/time formatter uses to format and parse a time.
static DateFormatgetTimeInstance()Gets the time formatter with the default formatting style for the default locale.
static DateFormatgetTimeInstance(int style)Gets the time formatter with the given formatting style for the default locale.
static DateFormatgetTimeInstance(int style, Locale aLocale)Gets the time formatter with the given formatting style for the given locale.
TimeZonegetTimeZone()Gets the time zone.

Get all locales

ReturnMethodSummary
static Locale[]getAvailableLocales()Returns an array of all locales for which the get*Instance methods of this class can return localized instances.

Is date/time parsed lenient

ReturnMethodSummary
booleanisLenient()Tell whether date/time parsing is to be lenient.

Parse string to get Date

ReturnMethodSummary
Dateparse(String source)Parses text from the beginning of the given string to produce a date.
ObjectparseObject(String source, ParsePosition pos)Parses text from a string to produce a Date.

Change the date formatter

ReturnMethodSummary
voidsetCalendar(Calendar newCalendar)Set the calendar to be used by this date format.
voidsetLenient(boolean lenient)Specify whether or not date/time parsing is to be lenient.
voidsetNumberFormat(NumberFormat newNumberFormat)Allows you to set the number formatter.
voidsetTimeZone(TimeZone zone)Sets the time zone for the calendar of this DateFormat object.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.