exsltdatetime.java

来自「java jdk 1.4的源码」· Java 代码 · 共 958 行 · 第 1/3 页

JAVA
958
字号
      return new XNumber(getNumber(datetime, formats, Calendar.MONTH));    }        /**     * See above.     */    public static XNumber monthInYear()    {            Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.MONTH));   }        /**     * The date:week-in-year function returns the week of the year as a number. If no argument      * is given, then the current local date/time, as returned by date:date-time is used as the      * default argument. For the purposes of numbering, counting follows ISO 8601: week 1 in a year      * is the week containing the first Thursday of the year, with new weeks beginning on a Monday.      * The date/time string specified as the argument is a right-truncated string in the format      * defined as the lexical representation of xs:dateTime in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>. The      * permitted formats are as follows:      *    xs:dateTime (CCYY-MM-DDThh:mm:ss)      *    xs:date (CCYY-MM-DD)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber weekInYear(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                  String[] formats = {dt, d};      return new XNumber(getNumber(datetime, formats, Calendar.WEEK_OF_YEAR));    }            /**     * See above.     */    public static XNumber weekInYear()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.WEEK_OF_YEAR));   }    /**     * The date:day-in-year function returns the day of a date in a year      * as a number. If no argument is given, then the current local     * date/time, as returned by date:date-time is used the default argument.     * The date/time string specified as the argument is a right-truncated      * string in the format defined as the lexical representation of xs:dateTime     * in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:     *     xs:dateTime (CCYY-MM-DDThh:mm:ss)     *     xs:date (CCYY-MM-DD)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber dayInYear(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                        String[] formats = {dt, d};      return new XNumber(getNumber(datetime, formats, Calendar.DAY_OF_YEAR));    }        /**     * See above.     */    public static XNumber dayInYear()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.DAY_OF_YEAR));   }        /**     * The date:day-in-month function returns the day of a date as a number.      * If no argument is given, then the current local date/time, as returned      * by date:date-time is used the default argument.      * The date/time string specified as the argument is a left or right-truncated      * string in the format defined as the lexical representation of xs:dateTime      * in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *      xs:dateTime (CCYY-MM-DDThh:mm:ss)      *      xs:date (CCYY-MM-DD)      *      xs:gMonthDay (--MM-DD)      *      xs:gDay (---DD)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber dayInMonth(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      String[] formats = {dt, d, gmd, gd};      double day = getNumber(datetime, formats, Calendar.DAY_OF_MONTH);      return new XNumber(day);    }        /**     * See above.     */    public static XNumber dayInMonth()    {      Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.DAY_OF_MONTH));   }        /**     * The date:day-of-week-in-month function returns the day-of-the-week      * in a month of a date as a number (e.g. 3 for the 3rd Tuesday in May).      * If no argument is given, then the current local date/time, as returned      * by date:date-time is used the default argument.      * The date/time string specified as the argument is a right-truncated string     * in the format defined as the lexical representation of xs:dateTime in one      * of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *      xs:dateTime (CCYY-MM-DDThh:mm:ss)      *      xs:date (CCYY-MM-DD)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber dayOfWeekInMonth(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                  String[] formats =  {dt, d};      return new XNumber(getNumber(datetime, formats, Calendar.DAY_OF_WEEK_IN_MONTH));    }        /**     * See above.     */    public static XNumber dayOfWeekInMonth()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));   }              /**     * The date:day-in-week function returns the day of the week given in a      * date as a number. If no argument is given, then the current local date/time,      * as returned by date:date-time is used the default argument.      * The date/time string specified as the argument is a right-truncated string      * in the format defined as the lexical representation of xs:dateTime in one      * of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *      xs:dateTime (CCYY-MM-DDThh:mm:ss)      *      xs:date (CCYY-MM-DD)      * If the date/time string is not in one of these formats, then NaN is returned.                             The numbering of days of the week starts at 1 for Sunday, 2 for Monday and so on up to 7 for Saturday.       */    public static XNumber dayInWeek(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                  String[] formats = {dt, d};      return new XNumber(getNumber(datetime, formats, Calendar.DAY_OF_WEEK));    }        /**     * See above.     */    public static XNumber dayInWeek()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.DAY_OF_WEEK));   }            /**     * The date:hour-in-day function returns the hour of the day as a number.      * If no argument is given, then the current local date/time, as returned      * by date:date-time is used the default argument.      * The date/time string specified as the argument is a right-truncated      * string  in the format defined as the lexical representation of xs:dateTime     * in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *     xs:dateTime (CCYY-MM-DDThh:mm:ss)      *     xs:time (hh:mm:ss)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber hourInDay(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                        String[] formats = {d, t};      return new XNumber(getNumber(datetime, formats, Calendar.HOUR_OF_DAY));    }        /**     * See above.     */    public static XNumber hourInDay()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.HOUR_OF_DAY));   }        /**     * The date:minute-in-hour function returns the minute of the hour      * as a number. If no argument is given, then the current local     * date/time, as returned by date:date-time is used the default argument.      * The date/time string specified as the argument is a right-truncated      * string in the format defined as the lexical representation of xs:dateTime     * in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *      xs:dateTime (CCYY-MM-DDThh:mm:ss)      *      xs:time (hh:mm:ss)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber minuteInHour(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                        String[] formats = {dt,t};      return new XNumber(getNumber(datetime, formats, Calendar.MINUTE));    }            /**     * See above.     */   public static XNumber minuteInHour()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.MINUTE));   }        /**     * The date:second-in-minute function returns the second of the minute      * as a number. If no argument is given, then the current local      * date/time, as returned by date:date-time is used the default argument.      * The date/time string specified as the argument is a right-truncated      * string in the format defined as the lexical representation of xs:dateTime     * in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *      xs:dateTime (CCYY-MM-DDThh:mm:ss)      *      xs:time (hh:mm:ss)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XNumber secondInMinute(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                        String[] formats = {dt, t};      return new XNumber(getNumber(datetime, formats, Calendar.SECOND));    }    /**     * See above.     */    public static XNumber secondInMinute()    {       Calendar cal = Calendar.getInstance();      return new XNumber(cal.get(Calendar.SECOND));    }           /**     * The date:leap-year function returns true if the year given in a date      * is a leap year. If no argument is given, then the current local     * date/time, as returned by date:date-time is used as a default argument.      * The date/time string specified as the first argument must be a      * right-truncated string in the format defined as the lexical representation     * of xs:dateTime in one of the formats defined in      * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.      * The permitted formats are as follows:      *    xs:dateTime (CCYY-MM-DDThh:mm:ss)      *    xs:date (CCYY-MM-DD)      *    xs:gYearMonth (CCYY-MM)      *    xs:gYear (CCYY)      * If the date/time string is not in one of these formats, then NaN is returned.      */    public static XObject leapYear(String datetimeIn)      throws ParseException    {      String[] edz = getEraDatetimeZone(datetimeIn);      String datetime = edz[1];      if (datetime == null)         return new XNumber(Double.NaN);                              String[] formats = {dt, d, gym, gy};      double dbl = getNumber(datetime, formats, Calendar.YEAR);      if (dbl == Double.NaN)         return new XNumber(Double.NaN);      int yr = (int)dbl;      return new XBoolean(yr % 400 == 0 || (yr % 100 != 0 && yr % 4 == 0));    }        /**

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?