/** * See above. */ public static String date() { String datetime = dateTime(); String date = datetime.substring(0, datetime.indexOf("T")); String zone = datetime.substring(getZoneStart(datetime)); return (date + zone); }
buff.append(posneg + formatDigits(hrs) + ':' + formatDigits(min));
/** * 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 double dayInYear(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_YEAR); }
throws ParseException String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return getNameOrAbbrev(datetimeIn, formatsIn, formatOut);
throws ParseException String[] edz = getEraDatetimeZone(timeIn); String time = edz[1]; String zone = edz[2]; Date date = testFormats(time, formatsIn); if (date == null) return EMPTY_STR; SimpleDateFormat dateFormat = new SimpleDateFormat(formatOut);
/** * See above. */ public static String dayAbbreviation() { String format = "EEE"; return getNameOrAbbrev(format); }
/** * Parse the input string and return the corresponding calendar field * number. */ private static double getNumber(String in, String[] formats, int calField) throws ParseException { Calendar cal = Calendar.getInstance(); cal.setLenient(false); // Try the allowed formats, from longest to shortest. Date date = testFormats(in, formats); if (date == null) return Double.NaN; cal.setTime(date); return cal.get(calField); }
/** * See above. */ public static String time() { String datetime = dateTime(); String time = datetime.substring(datetime.indexOf("T")+1); // The datetime() function returns the zone on the datetime string. If we // append it, we get the zone substring duplicated. // Fix for JIRA 2013 // String zone = datetime.substring(getZoneStart(datetime)); // return (time + zone); return (time); }
/** * Returns an array with the 3 components that a datetime input string * may contain: - (for BC era), datetime, and zone. If the zone is not * valid, return null for that component. */ private static String[] getEraDatetimeZone(String in) { String leader = ""; String datetime = in; String zone = ""; if (in.charAt(0)=='-' && !in.startsWith("--")) { leader = "-"; // '+' is implicit , not allowed datetime = in.substring(1); } int z = getZoneStart(datetime); if (z > 0) { zone = datetime.substring(z); datetime = datetime.substring(0, z); } else if (z == -2) zone = null; //System.out.println("'" + leader + "' " + datetime + " " + zone); return new String[]{leader, datetime, zone}; }
inFormat.setLenient(false); Date d= inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip (yearSymbols + monthSymbols + daySymbols, pattern)); outFormat.setTimeZone(timeZone); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols + monthSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d);
throws ParseException String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return getNameOrAbbrev(datetimeIn, formatsIn, formatOut);
throws ParseException String[] edz = getEraDatetimeZone(datetimeIn); String leader = edz[0]; String datetime = edz[1]; Date date = testFormats(datetime, formatsIn); if (date == null) return EMPTY_STR;
/** * See above. */ public static String monthName() { String format = "MMMM"; return getNameOrAbbrev(format); }
/** * Parse the input string and return the corresponding calendar field * number. */ private static double getNumber(String in, String[] formats, int calField) throws ParseException { Calendar cal = Calendar.getInstance(); cal.setLenient(false); // Try the allowed formats, from longest to shortest. Date date = testFormats(in, formats); if (date == null) return Double.NaN; cal.setTime(date); return cal.get(calField); }
/** * See above. */ public static String time() { String datetime = dateTime(); String time = datetime.substring(datetime.indexOf("T")+1); // The datetime() function returns the zone on the datetime string. If we // append it, we get the zone substring duplicated. // Fix for JIRA 2013 // String zone = datetime.substring(getZoneStart(datetime)); // return (time + zone); return (time); }
/** * Returns an array with the 3 components that a datetime input string * may contain: - (for BC era), datetime, and zone. If the zone is not * valid, return null for that component. */ private static String[] getEraDatetimeZone(String in) { String leader = ""; String datetime = in; String zone = ""; if (in.charAt(0)=='-' && !in.startsWith("--")) { leader = "-"; // '+' is implicit , not allowed datetime = in.substring(1); } int z = getZoneStart(datetime); if (z > 0) { zone = datetime.substring(z); datetime = datetime.substring(0, z); } else if (z == -2) zone = null; //System.out.println("'" + leader + "' " + datetime + " " + zone); return new String[]{leader, datetime, zone}; }
inFormat.setLenient(false); Date d= inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip (yearSymbols + monthSymbols + daySymbols, pattern)); outFormat.setTimeZone(timeZone); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d); inFormat.setLenient(false); Date d = inFormat.parse(dateTime); SimpleDateFormat outFormat = new SimpleDateFormat(strip(yearSymbols + monthSymbols, pattern)); outFormat.setTimeZone(timeZone); return outFormat.format(d);
/** * 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 double weekInYear(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.WEEK_OF_YEAR); }
throws ParseException String[] edz = getEraDatetimeZone(datetimeIn); String datetime = edz[1]; if (datetime == null) return getNameOrAbbrev(datetimeIn, formatsIn, formatOut);
throws ParseException String[] edz = getEraDatetimeZone(timeIn); String time = edz[1]; String zone = edz[2]; Date date = testFormats(time, formatsIn); if (date == null) return EMPTY_STR; SimpleDateFormat dateFormat = new SimpleDateFormat(formatOut);