|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Date
org.clapper.util.misc.XDate
public class XDate
Version of java.util.Date that provides some extra utility functions.
| Constructor Summary | |
|---|---|
XDate()
Create a new XDate so that it represents the time the object was constructed, measure to the nearest millisecond. |
|
XDate(java.util.Date date)
Create a new XDate object and initialize it to represent the time contained in the specified, existing Date object (which may, itself, be an XDate). |
|
XDate(long millis)
Create a new XDate object and initialize it to represent the specified number of milliseconds since the epoch. |
|
| Method Summary | |
|---|---|
XDate |
convertToTimeZone(java.util.TimeZone tz)
Convert this date from its time zone to another. |
java.lang.String |
formatInTimeZone(java.lang.String dateFormat,
java.util.TimeZone tz)
Convenience method to produce a printable date in a specified time zone, using a SimpleDateFormat. |
| Methods inherited from class java.util.Date |
|---|
after, before, clone, compareTo, equals, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, toString, UTC |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public XDate()
public XDate(long millis)
millis - the millisecondspublic XDate(java.util.Date date)
date - the date| Method Detail |
|---|
public XDate convertToTimeZone(java.util.TimeZone tz)
// Convert time in default time zone to UTC
XDate now = new XDate();
TimeZone tzUTC = TimeZone.getTimeZone ("UTC");
Date utc = now.convertToTimeZone (tzUTC);
DateFormat fmt = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss z");
fmt.setTimeZone (tzUTC);
System.out.println (fmt.format (utc));
Or, more simply:
XDate now = new XDate();
System.out.println (now.formatInTimeZone ("yyyy/MM/dd HH:mm:ss z",
TimeZone.getTimeZone ("UTC")));
tz - the time zone to convert the date to
formatInTimeZone(java.lang.String, java.util.TimeZone)
public java.lang.String formatInTimeZone(java.lang.String dateFormat,
java.util.TimeZone tz)
XDate now = new XDate();
TimeZone tzUTC = TimeZone.getTimeZone ("UTC");
Date utc = now.convertToTimeZone (tzUTC);
DateFormat fmt = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss z");
fmt.setTimeZone (tzUTC);
String formattedDate = fmt.format (utc);
dateFormat - the date format string to use, in a form that's
compatible with java.text.SimpleDateFormattz - the desired time zone
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||