java-gnome version 4.0.19

org.freedesktop.bindings
Class Time

Object
  extended by org.freedesktop.bindings.Time

public class Time
extends Object

Utility functions to format date/time groups in timezone aware fashion. These methods work off the timezone data installed on your system and are accessed directly through the standard C library.

Since:
4.0.5
Author:
Andrew Cowie

Method Summary
static String formatTime(String format, long when)
          Output the date per the descriptor given in the format parameter.
static long makeTime(int year, int month, int day, int hour, int minute, int second)
          Compose a timestamp (the number of seconds since epoch) from individual components of a date/time group.
static void setTimeZone(String zoneinfo)
          Adjust the timezone being used for formatted time/date output calculations.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatTime

public static String formatTime(String format,
                                long when)
Output the date per the descriptor given in the format parameter.

Feel free to call this several times to get isolated Strings with just the bits you want. For example, we do

 long when;
 
 when = System.currentTimeMillis();
 
 ... = formatTime("%H:%M", when);
 ... = formatTime("%a,%e %b %y", when);
 ... = formatTime("%Z", when);
 
in quick succession to get time, date, and timezone, respectively, just the way we like it.

This is a wrapper around strftime() from the standard C library. It is exposed because the formatting is done according to the value of the TZ environment variable, which in turn draws from the system zoneinfo libraries, data which is much more up to date than what Java offers.

Parameters:
when - the number of seconds since Epoch being the date/time group you wish to present according to format.
See Also:
strftime(3)

makeTime

public static long makeTime(int year,
                            int month,
                            int day,
                            int hour,
                            int minute,
                            int second)
Compose a timestamp (the number of seconds since epoch) from individual components of a date/time group. Takes into account the current system timezone setting.

This is essentially a wrapper around mktime().

Parameters:
year - the year, four digits
month - the month, range 1-12
day - the day, range 1-{28,29,30,31} (depending on the month, of course)
hour - the hour, range 0-23
minute - the minute, 0-59
second - the second, 0-59
See Also:
mktime(3)

setTimeZone

public static void setTimeZone(String zoneinfo)
Adjust the timezone being used for formatted time/date output calculations.

This will change the timezone as far as the entire program is concerned. If you have some reason to restore the original setting, use getEnv().

This works by changing the environment variable TZ and then calling tzset(). That may or may not be what you want. We've made it static since this impacts the entire process. If someone can figure out a way to change the timezone that strftime() thinks it is in without doing this, then please let us know.

Parameters:
zoneinfo - A String of the form "Australia/Sydney", "America/Toronto", "America/New_York", or "Europe/London", etc. Some zones have definitive abbreviations, notably Universal Time, Co-ordinated as "UTC". In case it wasn't obvious, these are files in /usr/share/zoneinfo/ and are relative to that path.
See Also:
tzset(3)


java-gnome