Class LcTime

  • Direct Known Subclasses:
    ISOTime

    public class LcTime
    extends 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 Detail

      • LcTime

        public LcTime​(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,
                      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​(String time,
                      String pat,
                      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 String format​(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 String getLocalTimeFormat​(int style,
                                                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 String getTimeFormat​(int style,
                                           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 String toString()
        Formats this object according to the default pattern.
        Overrides:
        toString in class Object
        Returns:
        the time string formatted according to the default pattern, upon success, and the empty string, upon error.