|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd.api.common.TLptsTimeUtil
public class TLptsTimeUtil
Class Description : These are utilities for time formatting and manipulation.
Field Summary | |
---|---|
static java.lang.String |
DATE_DD_MM_YY_HH_MM
|
static java.lang.String |
DATE_DD_MM_YYYY
|
static java.lang.String |
DATE_DDMMYY_HH_MM_1
|
static java.lang.String |
DATE_DDMMYY_HH_MM_2
|
static java.lang.String |
DATE_DDMMYY_HH_MM_SS_1
|
static java.lang.String |
DATE_DDMMYY_HH_MM_SS_2
|
static java.lang.String |
DATE_DDMMYY_HH_MM_SS_3
|
static java.lang.String |
DATE_DDMMYY_HH_MM_SS_S
|
static java.lang.String |
DATE_DDMMYYYY
|
static java.lang.String |
DATE_MM_DD_YY_HH_MM
|
static java.lang.String |
DATE_MM_DD_YYYY
|
static java.lang.String |
DATE_MMDDYY_HH_MM_1
|
static java.lang.String |
DATE_MMDDYY_HH_MM_2
|
static java.lang.String |
TIME_HH_MM
|
static java.lang.String |
TIME_HH_MM_SS
|
static java.lang.String |
TIME_HH_MM_SS_SSS
|
Method Summary | |
---|---|
static java.util.Date |
createDate(int year,
int month,
int day,
int hour,
int min,
int sec)
Creates a date and time object from the input information, with the local timezone. |
static java.util.Date |
createDate(int year,
int month,
int day,
int hour,
int min,
int sec,
int timezone)
Creates a date and time object from the input information, with any timezone. |
static java.sql.Timestamp |
getCurrentTime()
Gets the current Local Time. |
static java.lang.String |
getDateString(java.util.Date date,
boolean isMonthFirst,
boolean isDescription)
Gets the date supplied in a string format. |
static java.lang.String |
getTimeString(java.util.Date date)
Gets the time supplied in a string format. |
static java.lang.String |
getTimeString(java.util.Date date,
java.lang.String format)
Gets the time string with the specified format. |
static java.lang.String |
getTimeStringForZone(java.util.Date date,
java.lang.String format,
int timezone)
Get specific date format. |
static void |
zI()
Obfuscated, as it is not required by the application. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DATE_DD_MM_YY_HH_MM
public static final java.lang.String DATE_DD_MM_YYYY
public static final java.lang.String DATE_DDMMYY_HH_MM_1
public static final java.lang.String DATE_DDMMYY_HH_MM_2
public static final java.lang.String DATE_DDMMYY_HH_MM_SS_1
public static final java.lang.String DATE_DDMMYY_HH_MM_SS_2
public static final java.lang.String DATE_DDMMYY_HH_MM_SS_3
public static final java.lang.String DATE_DDMMYY_HH_MM_SS_S
public static final java.lang.String DATE_DDMMYYYY
public static final java.lang.String DATE_MM_DD_YY_HH_MM
public static final java.lang.String DATE_MM_DD_YYYY
public static final java.lang.String DATE_MMDDYY_HH_MM_1
public static final java.lang.String DATE_MMDDYY_HH_MM_2
public static final java.lang.String TIME_HH_MM
public static final java.lang.String TIME_HH_MM_SS
public static final java.lang.String TIME_HH_MM_SS_SSS
Method Detail |
---|
public static java.util.Date createDate(int year, int month, int day, int hour, int min, int sec)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes :
Example :
TLptsTimeUtil.createDate(2010, 1, 1, 0, 0, 0); // 2010 - Happy New Year! (local time)
year
- The year with 4 digits (ie 2010)month
- 1-12day
- 1-31hour
- 1-23min
- 0-59sec
- 0-59
public static java.util.Date createDate(int year, int month, int day, int hour, int min, int sec, int timezone)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes :
Example :
TLptsTimeUtil.createDate(2010, 1, 1, 0, 0, 0, 12); // New Zealand time // 2010 - The first timezone to see New Year's day.
year
- The year with 4 digits (ie 2010)month
- 1-12day
- 1-31hour
- 1-23min
- 0-59sec
- 0-59timezone
- From -12 to +12 depending on the longitudinal timezone required.
public static java.sql.Timestamp getCurrentTime()
Gets the current Local Time.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
Timestamp time = getCurrentTime(); TLptsTimeUtil.getTimeStringForZone(new Date(time.getTime()),"yyyy-MM-dd HH-mm-ss",0);
public static java.lang.String getDateString(java.util.Date date, boolean isMonthFirst, boolean isDescription)
The string supplied can be configured to the US format of month first,
or the day can be put first.
Furthermore, a description can be supplied at the end of the string as to the format.
e.i. (dd-mm-yyyy) or (mm-dd-yyyy) so that the reader knows which format the date is written in.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
String dateString = TLptsTimeUtil.getDateString(new Date(0),true,true); System.out.println("Today's date is " + dateString); Result: Today's date is 12-01-2009 (mm-dd-yyyy)
date
- The date to be translated into a stringisMonthFirst
- If true the month is put first (mm-dd-yyyy), otherwise the day is put first.isDescription
- If true the end of the string shows the format of the date (dd-mm-yyyy).
public static java.lang.String getTimeString(java.util.Date date)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
String timeString = TLptsTimeUtil.getTimeString(new Date()); System.out.println("Time is " + timeString); Result: Time is 12:56:57.628
date
- the date to get as String.
public static java.lang.String getTimeString(java.util.Date date, java.lang.String format)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : The time is converted to the default (normally local) timezone of the host system.
The timezone of the Date supplied is used to convert the time to the default timezone.
WARNING : DO NOT USE THIS FOR CONVERTING TIMEZONES. TEST HAVE SHOWN THAT THE CONVERSION IS NOT PERFORMED
CORRECTLY. THE ONLY CONSISTENT RESULTS ARE ACHIEVED FROM DATES THAT ARE GENERATED FROM DEFAULT TIME.
IN OTHER WORDS CREATEDATE (WITHOUT TIMEZONE) AND NEW DATE().
TO CONVERT TIMEZONES, USE CREATEDATE (WITH TIMEZONE) AND GETTIMESTRINGFORZONE.
For the format of the string use the characters below to indicate the required parts of the date/time.
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Number 1996; 96
M Month in year July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
Example :
Date date = TLptsTimeUtil.createDate(2010, 12, 13, 10, 20, 30); // local timezone String strDate = TLptsTimeUtil.getTimeString(date,TLptsTimeUtil.DATE_DD_MM_YY_HH_MM); // local timezone Result 13-12-10 10:20 // no conversion for the timezones
date
- The time to format.format
- The format for the time.
public static java.lang.String getTimeStringForZone(java.util.Date date, java.lang.String format, int timezone)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : Time is converted to the timezone requested, from the timezone in the date supplied.
USE the 'z' or 'Z' in the table below, to show the time zone information.
For the format of the string use the characters below to indicate the required parts of the date/time.
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Number 1996; 96
M Month in year July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
Example :
Date date = TLptsTimeUtil.createDate(2010, 12, 13, 10, 20, 30, 2); // timezone = GMT+2:00 : 10:20:30 String strDate = TLptsTimeUtil.getTimeStringForZone(date,TLptsTimeUtil.DATE_DD_MM_YY_HH_MM,2); // timezone = GMT+2:00 Result 13-12-10 10:20 // no conversion for the timezones Date date = TLptsTimeUtil.createDate(2010, 12, 13, 10, 20, 30, 12); // timezone = GMT+12:00 New Zealand : 10:20:30 String strDate = TLptsTimeUtil.getTimeStringForZone(date,TLptsTimeUtil.DATE_DD_MM_YY_HH_MM,2); // timezone = GMT+2:00 Result 13-12-10 00:20 // 10 hour time difference. Date date = TLptsTimeUtil.createDate(2010, 12, 13, 10, 20, 30, -8); // timezone = GMT-8:00 USA : 10:20:30 String strDate = TLptsTimeUtil.getTimeStringForZone(date,TLptsTimeUtil.DATE_DD_MM_YY_HH_MM,2); // timezone = GMT+2:00 Result 13-12-10 20:20 // 10 hour time difference the other way.
date
- Time with its own timezone, which is converted to the requested timezone.format
- the time format that is required (as per the key above).timezone
- from -12 to 12, depending on the longitude position on the earth.
This is the required timezone. The time provided is converted to this timezone before the string is created.
This value is modulated to 12, if it is outside the bounds.
public static void zI()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |