vooga.engine.resource.clock
Class WorldClock

java.lang.Object
  extended by vooga.engine.resource.clock.WorldClock

public class WorldClock
extends java.lang.Object

Allows for checking the time in the local time zone and Coordinated Universal Time (UTC). The local time zone by default is UTC, but this can be set to any time zone using the TimeZone class or any time zone unique string ids set up by the TimeZone class such as "EST" or "Pacific Standard Time" or "GMT+10" or "America/Los_Angelos". A complete list of available time zones can be found at http://mindprod.com/jgloss/timezone.html The local or UTC time can be retrieved as milliseconds since January 1, 1970 00:00:00.00 Individual components of the time from the number of milliseconds in the current time to the current year can also be retrieved. This class can be used to create game events which depend on real world time. For instance, the background of the game could change to mirror the time of day; scenery in the game could reflect the real world season; after 1 hour of the game being open irrespective of how long the game has been running according the game clock the game could display a message telling the user to take a break and go outside like the Wii. WorldClock is dependent upon java.util.Calendar and java.util.TimeZone.


Field Summary
static int DAY
           
static int HOUR
           
static int MILLISECOND
           
static int MINUTE
           
static int MONTH
           
static int SECOND
           
static int YEAR
           
 
Constructor Summary
WorldClock()
           
 
Method Summary
static long getLocalTime()
          Returns the current local time measured as millisecond from January 1, 1970 00:00.00 in the local time zone.
static int getLocalTime(int type)
          Returns an individual component of the local time and date.
static long getUTCTime()
          Returns the current local time measured as millisecond from January 1, 1970 00:00.00 in Coordinated Universal Time.
static int getUTCTime(int type)
          Returns an individual component of the UTC time and date.
static void setTimeZone(java.lang.String timeZoneSID)
          Set the local time zone with a time zone String id.
static void setTimeZone(java.util.TimeZone tz)
          Set the local time zone using a TimeZone object set to the correct time zone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLISECOND

public static final int MILLISECOND
See Also:
Constant Field Values

SECOND

public static final int SECOND
See Also:
Constant Field Values

MINUTE

public static final int MINUTE
See Also:
Constant Field Values

HOUR

public static final int HOUR
See Also:
Constant Field Values

DAY

public static final int DAY
See Also:
Constant Field Values

MONTH

public static final int MONTH
See Also:
Constant Field Values

YEAR

public static final int YEAR
See Also:
Constant Field Values
Constructor Detail

WorldClock

public WorldClock()
Method Detail

setTimeZone

public static void setTimeZone(java.util.TimeZone tz)
Set the local time zone using a TimeZone object set to the correct time zone. Local time and time/date components will be determined from this time zone.

Parameters:
tz - TimeZone object set to the local time zone

setTimeZone

public static void setTimeZone(java.lang.String timeZoneSID)
Set the local time zone with a time zone String id. Local time and time/date components will be determined from this time zone. Examples of time zone Strind ids include: "EST" or "Pacific Standard Time" or "GMT+10" or "America/Los_Angelos"

Parameters:
timeZoneSID - the String identification of the local time zone

getLocalTime

public static long getLocalTime()
Returns the current local time measured as millisecond from January 1, 1970 00:00.00 in the local time zone.

Returns:
number of milliseconds since January 1, 1970 00:00.00 in the local time zone.

getLocalTime

public static int getLocalTime(int type)
Returns an individual component of the local time and date. Available components are milliseconds, second, minutes, hours on a 24 hour clock, day, month, and year. For example, if in the local time zone it is April 13, 2008 17:32:42.04 - WorldClock.getLocalTime(WorldClock.MILLISECOND) returns 4 WorldClock.getLocalTime(WorldClock.SECOND) returns 42 WorldClock.getLocalTime(WorldClock.MINUTE) returns 32 WorldClock.getLocalTime(WorldClock.HOUR) returns 17 WorldClock.getLocalTime(WorldClock.DAY) returns 13 WorldClock.getLocalTime(WorldClock.MONTH) returns 4 WorldClock.getLocalTime(WorldClock.HOUR) returns 2008

Parameters:
integer - uniquely identifying desired time/date component. These ids are static constants of the WorldClock class.
Returns:
requested component of the local date/time

getUTCTime

public static long getUTCTime()
Returns the current local time measured as millisecond from January 1, 1970 00:00.00 in Coordinated Universal Time. This is also the system time.

Returns:
number of milliseconds since January 1, 1970 00:00.00 UTC

getUTCTime

public static int getUTCTime(int type)
Returns an individual component of the UTC time and date. Available components are milliseconds, second, minutes, hours on a 24 hour clock, day, month, and year. For example, if the UTC time and date is April 13, 2008 17:32:42.04 - WorldClock.getLocalTime(WorldClock.MILLISECOND) returns 4 WorldClock.getLocalTime(WorldClock.SECOND) returns 42 WorldClock.getLocalTime(WorldClock.MINUTE) returns 32 WorldClock.getLocalTime(WorldClock.HOUR) returns 17 WorldClock.getLocalTime(WorldClock.DAY) returns 13 WorldClock.getLocalTime(WorldClock.MONTH) returns 4 WorldClock.getLocalTime(WorldClock.HOUR) returns 2008

Parameters:
integer - uniquely identifying desired time/date component. These ids are static constants of the WorldClock class.
Returns:
requested component of the UTC date/time