public class DateTimeService extends Object
| Constructor and Description |
|---|
DateTimeService()
Creates a new date time service with the application default locale.
|
DateTimeService(String locale)
Creates a new date time service with a given locale.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
asTwoDigits(int i)
Utility method to format positive int as zero-padded two-digits number.
|
String |
formatDate(Date date,
String formatStr)
Check if format contains the month name.
|
String |
formatDate(Date date,
String formatStr,
com.google.gwt.i18n.client.TimeZone timeZone)
Check if format contains the month name.
|
String[] |
getAmPmStrings() |
String |
getClockDelimeter() |
String |
getDay(int day) |
int |
getFirstDayOfWeek()
Returns the first day of the week, according to the used Locale.
|
static int |
getISOWeekNumber(Date date)
Returns the ISO-8601 week number of the given date.
|
String |
getLocale() |
static int |
getMilliseconds(Date date) |
String |
getMonth(int month) |
static int |
getNumberOfDaysInMonth(Date date) |
String |
getShortDay(int day)
Returns the localized short name of the specified day.
|
String |
getShortMonth(int month) |
int |
getStartWeekDay(Date month)
Returns the first day of week of the specified
month. |
static boolean |
isInRange(Date date,
Date rangeStart,
Date rangeEnd,
DateResolution resolution) |
static boolean |
isLeapYear(Date date) |
static boolean |
isSameDay(Date d1,
Date d2) |
boolean |
isTwelveHourClock()
Returns whether the locale has twelve hour, or twenty four hour clock.
|
Date |
parseDate(String dateString,
String formatString,
boolean lenient)
Parses the given date string using the given format string and the locale
set in this DateTimeService instance.
|
void |
setLocale(String locale) |
static void |
setMilliseconds(Date date,
int ms) |
public DateTimeService()
public DateTimeService(String locale) throws LocaleNotLoadedException
locale - e.g. fi, en, etc.LocaleNotLoadedExceptionpublic static String asTwoDigits(int i)
i - the valuepublic void setLocale(String locale) throws LocaleNotLoadedException
LocaleNotLoadedExceptionpublic String getLocale()
public String getMonth(int month)
public String getShortMonth(int month)
public String getDay(int day)
public String getShortDay(int day)
day - the day, 0 is SUNDAYpublic int getFirstDayOfWeek()
0 is SUNDAYpublic boolean isTwelveHourClock()
true if the locale has twelve hour clock, false
for twenty four clockpublic String getClockDelimeter()
public String[] getAmPmStrings()
public int getStartWeekDay(Date month)
month.month - the month, not nullpublic static void setMilliseconds(Date date, int ms)
public static int getMilliseconds(Date date)
public static int getNumberOfDaysInMonth(Date date)
public static boolean isLeapYear(Date date)
public static boolean isInRange(Date date, Date rangeStart, Date rangeEnd, DateResolution resolution)
public static int getISOWeekNumber(Date date)
date - The date for which the week number should be resolvedpublic String formatDate(Date date, String formatStr)
date - The date to convertformatStr - The format string that might contain MMM or MMMMpublic String formatDate(Date date, String formatStr, com.google.gwt.i18n.client.TimeZone timeZone)
timeZoneJSONdate - The date to convertformatStr - The format string that might contain MMM or
MMMMtimeZone - The TimeZone used to replace z, can be
nullpublic Date parseDate(String dateString, String formatString, boolean lenient) throws IllegalArgumentException
dateString - Date string e.g. "1 February 2010"formatString - Format string e.g. "d MMMM yyyy"lenient - true to use lenient parsing, false to use strict parsingIllegalArgumentException - if the parsing failsCopyright © 2018 Vaadin Ltd. All rights reserved.