org.clapper.util.misc
Class XDate
- java.lang.Object
-
- java.util.Date
-
- org.clapper.util.misc.XDate
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>
public class XDate extends java.util.DateVersion of java.util.Date that provides some extra utility functions.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description XDateconvertToTimeZone(java.util.TimeZone tz)Convert this date from its time zone to another.java.lang.StringformatInTimeZone(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, from, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toInstant, toLocaleString, toString, UTC
-
-
-
-
Constructor Detail
-
XDate
public XDate()
Create a new XDate so that it represents the time the object was constructed, measure to the nearest millisecond.
-
XDate
public XDate(long millis)
Create a new XDate object and initialize it to represent the specified number of milliseconds since the epoch.- Parameters:
millis- the milliseconds
-
XDate
public 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).- Parameters:
date- the date
-
-
Method Detail
-
convertToTimeZone
public XDate convertToTimeZone(java.util.TimeZone tz)
Convert this date from its time zone to another. Sample use:// 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")));- Parameters:
tz- the time zone to convert the date to- Returns:
- a new XDate object, appropriately converted. This result can safely be stored in a java.util.Date reference.
- See Also:
formatInTimeZone(java.lang.String, java.util.TimeZone)
-
formatInTimeZone
public 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. Calling this method is roughly equivalent to: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);- Parameters:
dateFormat- the date format string to use, in a form that's compatible with java.text.SimpleDateFormattz- the desired time zone- Returns:
- the formatted date string
-
-
DMelt 3.0 © DataMelt by jWork.ORG