📄 exsltdatetime.java
字号:
* 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 double 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 day; } /** * See above. */ public static double dayInMonth() { Calendar cal = Calendar.getInstance(); return 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 double dayOfWeekInMonth(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return Double.NaN; String[] formats = {dt, d}; return getNumber(datetime, formats, Calendar.DAY_OF_WEEK_IN_MONTH); } /** * See above. */ public static double dayOfWeekInMonth() { Calendar cal = Calendar.getInstance(); return 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 double dayInWeek(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return Double.NaN; String[] formats = {dt, d}; return getNumber(datetime, formats, Calendar.DAY_OF_WEEK); } /** * See above. */ public static double dayInWeek() { Calendar cal = Calendar.getInstance(); return 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 double hourInDay(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return Double.NaN; String[] formats = {dt, t}; return getNumber(datetime, formats, Calendar.HOUR_OF_DAY); } /** * See above. */ public static double hourInDay() { Calendar cal = Calendar.getInstance(); return 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 double minuteInHour(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return Double.NaN; String[] formats = {dt,t}; return getNumber(datetime, formats, Calendar.MINUTE); } /** * See above. */ public static double minuteInHour() { Calendar cal = Calendar.getInstance(); return 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 double secondInMinute(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return Double.NaN; String[] formats = {dt, t}; return getNumber(datetime, formats, Calendar.SECOND); } /** * See above. */ public static double secondInMinute() { Calendar cal = Calendar.getInstance(); return 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)); } /** * See above. */ public static boolean leapYear() { Calendar cal = Calendar.getInstance(); int yr = (int)cal.get(Calendar.YEAR); return (yr % 400 == 0 || (yr % 100 != 0 && yr % 4 == 0)); } /** * The date:month-name function returns the full name of the month of a date. * 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:gYearMonth (CCYY-MM) * xs:gMonth (--MM--) * If the date/time string is not in one of these formats, then an empty string ('') * is returned. * The result is an English month name: one of 'January', 'February', 'March', * 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November' * or 'December'. */ public static String monthName(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return EMPTY_STR; String[] formatsIn = {dt, d, gym, gm}; String formatOut = "MMMM"; return getNameOrAbbrev(datetimeIn, formatsIn, formatOut); } /** * See above. */ public static String monthName() { Calendar cal = Calendar.getInstance(); String format = "MMMM"; return getNameOrAbbrev(format); } /** * The date:month-abbreviation function returns the abbreviation of the month of * a date. 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:gYearMonth (CCYY-MM) * xs:gMonth (--MM--) * If the date/time string is not in one of these formats, then an empty string ('') * is returned. * The result is a three-letter English month abbreviation: one of 'Jan', 'Feb', 'Mar', * 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov' or 'Dec'. * An implementation of this extension function in the EXSLT date namespace must conform * to the behaviour described in this document. */ public static String monthAbbreviation(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return EMPTY_STR; String[] formatsIn = {dt, d, gym, gm}; String formatOut = "MMM"; return getNameOrAbbrev(datetimeIn, formatsIn, formatOut); } /** * See above. */ public static String monthAbbreviation() { String format = "MMM"; return getNameOrAbbrev(format); } /** * The date:day-name function returns the full name of the day of the week * of a date. 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) * If the date/time string is not in one of these formats, then the empty string ('') * is returned. * The result is an English day name: one of 'Sunday', 'Monday', 'Tuesday', 'Wednesday', * 'Thursday' or 'Friday'. * An implementation of this extension function in the EXSLT date namespace must conform * to the behaviour described in this document. */ public static String dayName(String datetimeIn) throws ParseException { String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return EMPTY_STR; String[] formatsIn = {dt, d}; String formatOut = "EEEE"; return getNameOrAbbrev(datetimeIn, formatsIn, formatOut); } /** * See above. */ public static String dayName() { String format = "EEEE"; return getNameOrAbbrev(format); } /** * The date:day-abbreviation function returns the abbreviation of the day
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -