XDate
org.clapper.util.misc

Class XDate

    • 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(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(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 String formatInTimeZone(String dateFormat,                      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.SimpleDateFormat
        tz - the desired time zone
        Returns:
        the formatted date string

SCaVis 2.1 © jWork.ORG