Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)

com.lapetus_ltd.api.common
Class TLptsTimeUtil

java.lang.Object
  extended by com.lapetus_ltd.api.common.TLptsTimeUtil

public class TLptsTimeUtil
extends java.lang.Object

Class Description : These are utilities for time formatting and manipulation.

Use these utilities to get and control the output of time in the GUI.
You can also perform time conversions for global processing.

$LastChangedRevision: 1179 $
$LastChangedDate:: 2010-11-12 10:13:56#$


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

DATE_DD_MM_YY_HH_MM

public static final java.lang.String DATE_DD_MM_YY_HH_MM
See Also:
Constant Field Values

DATE_DD_MM_YYYY

public static final java.lang.String DATE_DD_MM_YYYY
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_1

public static final java.lang.String DATE_DDMMYY_HH_MM_1
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_2

public static final java.lang.String DATE_DDMMYY_HH_MM_2
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_SS_1

public static final java.lang.String DATE_DDMMYY_HH_MM_SS_1
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_SS_2

public static final java.lang.String DATE_DDMMYY_HH_MM_SS_2
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_SS_3

public static final java.lang.String DATE_DDMMYY_HH_MM_SS_3
See Also:
Constant Field Values

DATE_DDMMYY_HH_MM_SS_S

public static final java.lang.String DATE_DDMMYY_HH_MM_SS_S
See Also:
Constant Field Values

DATE_DDMMYYYY

public static final java.lang.String DATE_DDMMYYYY
See Also:
Constant Field Values

DATE_MM_DD_YY_HH_MM

public static final java.lang.String DATE_MM_DD_YY_HH_MM
See Also:
Constant Field Values

DATE_MM_DD_YYYY

public static final java.lang.String DATE_MM_DD_YYYY
See Also:
Constant Field Values

DATE_MMDDYY_HH_MM_1

public static final java.lang.String DATE_MMDDYY_HH_MM_1
See Also:
Constant Field Values

DATE_MMDDYY_HH_MM_2

public static final java.lang.String DATE_MMDDYY_HH_MM_2
See Also:
Constant Field Values

TIME_HH_MM

public static final java.lang.String TIME_HH_MM
See Also:
Constant Field Values

TIME_HH_MM_SS

public static final java.lang.String TIME_HH_MM_SS
See Also:
Constant Field Values

TIME_HH_MM_SS_SSS

public static final java.lang.String TIME_HH_MM_SS_SSS
See Also:
Constant Field Values
Method Detail

createDate

public 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.

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)
 

Parameters:
year - The year with 4 digits (ie 2010)
month - 1-12
day - 1-31
hour - 1-23
min - 0-59
sec - 0-59
Returns:
Returns null if any of the values are not valid or if the combination is invalid. Otherwise it returns a Date Object with the relative date set.

createDate

public 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.

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.
 

Parameters:
year - The year with 4 digits (ie 2010)
month - 1-12
day - 1-31
hour - 1-23
min - 0-59
sec - 0-59
timezone - From -12 to +12 depending on the longitudinal timezone required.
Returns:
Returns null if any of the values are not valid or if the combination is invalid. Otherwise it returns a Date Object with the relative date set.

getCurrentTime

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);
 
 

Returns:
current date and time as 2010-07-07 12:31:42.379

getDateString

public static java.lang.String getDateString(java.util.Date date,
                                             boolean isMonthFirst,
                                             boolean isDescription)
Gets the date supplied in a string format.

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)
 
 

Parameters:
date - The date to be translated into a string
isMonthFirst - 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).
Returns:
The formatted date string.

getTimeString

public static java.lang.String getTimeString(java.util.Date date)
Gets the time supplied in a string format.

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
 

Parameters:
date - the date to get as String.
Returns:
The format time string

getTimeString

public static java.lang.String getTimeString(java.util.Date date,
                                             java.lang.String format)
Gets the time string with the specified 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

 

Parameters:
date - The time to format.
format - The format for the time.
Returns:
Time as a formatted String.

getTimeStringForZone

public static java.lang.String getTimeStringForZone(java.util.Date date,
                                                    java.lang.String format,
                                                    int timezone)
Get specific date format.

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. 

 

Parameters:
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.
Returns:
the time converted to the requested time zone.

zI

public static void zI()
Obfuscated, as it is not required by the application.



Copyright 2009,2010, Lapetus Systems Ltd. (All rights reserved)