Class LcTime

  • Direct Known Subclasses:
    ISOTime

    public class LcTime
    extends java.lang.Object
    The LcTime class defines objects in support of XFA time picture patterns.

    The time is internally represented as the number of milliseconds from the epoch, which is midnight 00:00:00 GMT, i.e., time 1 is midnight GMT.

    Time picture patterns are used to parse and format time strings. Here are the metasymbols that form valid time picture patterns:

    h
    a one or two digit (1-12) hour of AM/PM.
    hh
    a two digit (01-12) hour of AM/PM.
    k
    a one or two digit (0-11) hour of AM/PM.
    kk
    a two digit (00-11) hour of AM/PM.
    H
    a one or two digit (0-23) hour of day.
    HH
    a two digit (00-23) hour of day.
    K
    a one or two digit (1-24) hour of day.
    KK
    a two digit (01-24) hour of day.
    M
    a one or two digit (0-59) minute of hour.
    MM
    a two digit (00-59) minute of hour.
    S
    a one or two digit (0-59) second of minute.
    SS
    a two digit (00-59) second of minute.
    FFF
    a three digit (000-999) thousandth of second.
    A
    a meridiem name (AM/PM) of the ambient locale.
    Z
    an abbreviated time zone name of the ambient locale.
    z
    an ISO8601 time zone format: Z, +HH[MM], -HH[MM].
    zz
    an alternate ISO8601 time zone format: Z, +HH[:MM], -HH[:MM].
    Here's a snippet of code illustrating the use of LcTime to reformat a time string
    
     
           import com.adobe.xfa.ut.LcTime;            // for defn of LcTime.
           ...
           String loc = "en_ca"
           String fmt = LcTime.DEFAULT_TIME_FMT;
           LcTime now = new LcTime(loc);
           now.setLocalTime();
           now += 2 * LcTime.MILLISPERHOUR;
           if (now.isValid())
               System.out.println(now.format("h:MM:SS:FFF A Z"));
      
     
    • Constructor Summary

      Constructors 
      Constructor Description
      LcTime​(int millis, java.lang.String locale)
      Instantiates an LcTime object from the number of milliseconds from the epoch and in the locale given.
      LcTime​(LcTime oTime)
      Instantiates an LcTime object from an existing LcTime object
      LcTime​(java.lang.String locale)
      Instantiates an LcTime object from today's Greenwich Mean time and in the locale given.
      LcTime​(java.lang.String time, java.lang.String pat, java.lang.String locale)
      Instantiates an LcTime object from the given time in the pattern given and in the locale given.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      LcTime add​(int millis)
      Adds the given milliseconds to this object.
      LcTime asgn​(LcTime oTime)
      Assigns the given LcTime object to this object.
      java.lang.String format​(java.lang.String pat)
      Formats this object given a time pattern string.
      int getDays()
      Gets this lcTime object's difference in days from Greenwich Mean.
      int getHour()
      Gets the hour of the day.
      static java.lang.String getLocalTimeFormat​(int style, java.lang.String locale)
      Gets the localized time pattern in the given style for the given locale.
      int getMillis()
      Gets the number of milliseconds since the epoch.
      int getMilliSecond()
      Gets the fraction of the second.
      int getMinute()
      Gets the minute of the hour.
      int getSecond()
      Gets the second of the hour.
      static java.lang.String getTimeFormat​(int style, java.lang.String locale)
      Gets the time pattern in the given style for the given locale.
      int getTimeZone()
      Get timezone in minutes west of Greenwich
      boolean isValid()
      Determines if this object is valid.
      void setGMTime()
      Sets this object to operate on Greenwich Mean time, which is the default.
      void setLocalTime()
      Sets this object to operate on local time as opposed to the default, which is Greenwich Mean time.
      java.lang.String toString()
      Formats this object according to the default pattern.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_TIME_FMT

        public static final java.lang.String DEFAULT_TIME_FMT
        Default LcTime pattern string for English_US locale: h:MM:SS A.
        See Also:
        Constant Field Values
      • TIME_FMT1

        public static final java.lang.String TIME_FMT1
        ISO8601/XFA time pattern string: HHMMSS.FFFz.
        See Also:
        Constant Field Values
      • TIME_FMT2

        public static final java.lang.String TIME_FMT2
        Alternate ISO8601/XFA time pattern string: HH:MM:SS.FFFzz.
        See Also:
        Constant Field Values
      • TIME_PICTURE_SYMBOLS

        public static final java.lang.String TIME_PICTURE_SYMBOLS
        LcTime pattern symbols: hkHKMSFAzZ.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LcTime

        public LcTime​(java.lang.String locale)
        Instantiates an LcTime object from today's Greenwich Mean time and in the locale given.
        Parameters:
        locale - a locale string. When empty, it will default to the default locale.
      • LcTime

        public LcTime​(int millis,
                      java.lang.String locale)
        Instantiates an LcTime object from the number of milliseconds from the epoch and in the locale given. The epoch is such that time 1 corresponds to midnight, 00:00:00 GMT.
        Parameters:
        millis - the number of milliseconds from epoch.
        locale - a locale string. When empty, it will default to the default locale.
      • LcTime

        public LcTime​(java.lang.String time,
                      java.lang.String pat,
                      java.lang.String locale)
        Instantiates an LcTime object from the given time in the pattern given and in the locale given.
        Parameters:
        time - a time string.
        pat - a time pattern string used to parse the given time.
        locale - a locale string. When empty, it will default to the default locale.
      • LcTime

        public LcTime​(LcTime oTime)
        Instantiates an LcTime object from an existing LcTime object
        Parameters:
        oTime - an existing LcTime object
    • Method Detail

      • add

        public LcTime add​(int millis)
        Adds the given milliseconds to this object.
        Parameters:
        millis - the number of milliseconds to add.
        Returns:
        this modified object.
      • asgn

        public LcTime asgn​(LcTime oTime)
        Assigns the given LcTime object to this object.
        Parameters:
        oTime - an existing LcTime object.
        Returns:
        this object.
      • format

        public java.lang.String format​(java.lang.String pat)
        Formats this object given a time pattern string.
        Parameters:
        pat - a time pattern string.
        Returns:
        the time string formatted according to the given pattern string, upon success, and the empty string, upon error.
      • getDays

        public int getDays()
        Gets this lcTime object's difference in days from Greenwich Mean.
        Returns:
        the number of days difference from GMT, or -366 if this object is invalid.
      • getHour

        public int getHour()
        Gets the hour of the day.
        Returns:
        the hour of the day in the range 0-23, or -1 if this object is invalid.
      • getLocalTimeFormat

        public static java.lang.String getLocalTimeFormat​(int style,
                                                          java.lang.String locale)
        Gets the localized time pattern in the given style for the given locale.
        Parameters:
        style - a style value:
        0
        requests the locale specific default-style time pattern,
        1
        requests the locale specific short-style time pattern,
        2
        requests the locale specific medium-style time pattern,
        3
        requests the locale specific long-style time pattern, and
        4
        requests the locale specific full-style time pattern.
        Any other value requests the default-style time pattern.
        locale - a locale string. When empty, it will default to the default locale.
        Returns:
        the requested time string.
      • getMillis

        public int getMillis()
        Gets the number of milliseconds since the epoch.
        Returns:
        the number of milliseconds, or 0 if this object is invalid.
      • getMilliSecond

        public int getMilliSecond()
        Gets the fraction of the second.
        Returns:
        the fraction of the second in the range 0-999, or -1 if this LcTime object is invalid.
      • getMinute

        public int getMinute()
        Gets the minute of the hour.
        Returns:
        the minute of the hour in the range 0-59, or -1 if this object is invalid.
      • getSecond

        public int getSecond()
        Gets the second of the hour.
        Returns:
        the second of the hour in the range 0-59, or -1 if this object is invalid.
      • getTimeFormat

        public static java.lang.String getTimeFormat​(int style,
                                                     java.lang.String locale)
        Gets the time pattern in the given style for the given locale.
        Parameters:
        style - a style value:
        0
        requests the locale specific default-style time pattern,
        1
        requests the locale specific short-style time pattern,
        2
        requests the locale specific medium-style time pattern,
        3
        requests the locale specific long-style time pattern, and
        4
        requests the locale specific full-style time pattern.
        Any other value requests the default-style time pattern.
        locale - a locale string. When empty, it will default to the default locale.
        Returns:
        the requested time string.
      • getTimeZone

        public int getTimeZone()
        Get timezone in minutes west of Greenwich
        Returns:
        timezone.
      • isValid

        public boolean isValid()
        Determines if this object is valid.
        Returns:
        boolean true if valid, and false otherwise.
      • setGMTime

        public void setGMTime()
        Sets this object to operate on Greenwich Mean time, which is the default. Any subsequent calls to the format method will result in time strings that are expressed in Greenwich Mean time.
      • setLocalTime

        public void setLocalTime()
        Sets this object to operate on local time as opposed to the default, which is Greenwich Mean time. Any subsequent calls to the format method will result in time strings that are expressed in local time.
      • toString

        public java.lang.String toString()
        Formats this object according to the default pattern.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the time string formatted according to the default pattern, upon success, and the empty string, upon error.