int year = parseInt(date, offset, offset += 4); checkOffset(date, offset, '-'); int month = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '-'); int day = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, 'T'); int hour = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int minutes = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int seconds = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '.'); milliseconds = parseInt(date, offset += 1, offset += 3);
/** * Format a date into 'yyyy-MM-ddThh:mm:ssZ' (GMT timezone, no milliseconds precision) * * @param date the date to format * @return the date formatted as 'yyyy-MM-ddThh:mm:ssZ' */ public static String format(Date date) { return format(date, false, TIMEZONE_GMT); }
StringBuilder formatted = new StringBuilder(capacity); padInt(formatted, calendar.get(Calendar.YEAR), "yyyy".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.MONTH) + 1, "MM".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), "dd".length()); formatted.append('T'); padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), "hh".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.MINUTE), "mm".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.SECOND), "ss".length()); if (millis) { formatted.append('.'); padInt(formatted, calendar.get(Calendar.MILLISECOND), "sss".length()); int minutes = Math.abs((offset / (60 * 1000)) % 60); formatted.append(offset < 0 ? '-' : '+'); padInt(formatted, hours, "hh".length()); formatted.append(':'); padInt(formatted, minutes, "mm".length()); } else { formatted.append('Z');
@Override public Date parse(String source, ParsePosition pos) { // index must be set to other than 0, I would swear this requirement is not there in // some version of jdk 6. pos.setIndex(source.length()); return ISO8601Utils.parse(source); }
@Override public Date parse(String source, ParsePosition pos) { // index must be set to other than 0, I would swear this requirement is not there in // some version of jdk 6. pos.setIndex(source.length()); return ISO8601Utils.parse(source); }
int year = parseInt(date, offset, offset += 4); checkOffset(date, offset, '-'); int month = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '-'); int day = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, 'T'); int hour = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int minutes = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int seconds = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '.'); milliseconds = parseInt(date, offset += 1, offset += 3);
/** * Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone) * * @param date the date to format * @param millis true to include millis precision otherwise false * @return the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z' */ public static String format(Date date, boolean millis) { return format(date, millis, TIMEZONE_GMT); }
@Override public Date parse(String source, ParsePosition pos) { // index must be set to other than 0, I would swear this requirement is not there in // some version of jdk 6. pos.setIndex(source.length()); return ISO8601Utils.parse(source); }
StringBuilder formatted = new StringBuilder(capacity); padInt(formatted, calendar.get(Calendar.YEAR), "yyyy".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.MONTH) + 1, "MM".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), "dd".length()); formatted.append('T'); padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), "hh".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.MINUTE), "mm".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.SECOND), "ss".length()); if (millis) { formatted.append('.'); padInt(formatted, calendar.get(Calendar.MILLISECOND), "sss".length()); int minutes = Math.abs((offset / (60 * 1000)) % 60); formatted.append(offset < 0 ? '-' : '+'); padInt(formatted, hours, "hh".length()); formatted.append(':'); padInt(formatted, minutes, "mm".length()); } else { formatted.append('Z');
int year = parseInt(date, offset, offset += 4); checkOffset(date, offset, '-'); int month = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '-'); int day = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, 'T'); int hour = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int minutes = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, ':'); int seconds = parseInt(date, offset += 1, offset += 2); checkOffset(date, offset, '.'); milliseconds = parseInt(date, offset += 1, offset += 3);
@Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { String value = ISO8601Utils.format(date); toAppendTo.append(value); return toAppendTo; }
StringBuilder formatted = new StringBuilder(capacity); padInt(formatted, calendar.get(Calendar.YEAR), "yyyy".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.MONTH) + 1, "MM".length()); formatted.append('-'); padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), "dd".length()); formatted.append('T'); padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), "hh".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.MINUTE), "mm".length()); formatted.append(':'); padInt(formatted, calendar.get(Calendar.SECOND), "ss".length()); if (millis) { formatted.append('.'); padInt(formatted, calendar.get(Calendar.MILLISECOND), "sss".length()); int minutes = Math.abs((offset / (60 * 1000)) % 60); formatted.append(offset < 0 ? '-' : '+'); padInt(formatted, hours, "hh".length()); formatted.append(':'); padInt(formatted, minutes, "mm".length()); } else { formatted.append('Z');
/** * Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone) * * @param date the date to format * @param millis true to include millis precision otherwise false * @return the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z' */ public static String format(Date date, boolean millis) { return format(date, millis, TIMEZONE_GMT); }
/** * Format a date into 'yyyy-MM-ddThh:mm:ssZ' (GMT timezone, no milliseconds precision) * * @param date the date to format * @return the date formatted as 'yyyy-MM-ddThh:mm:ssZ' */ public static String format(Date date) { return format(date, false, TIMEZONE_GMT); }
@Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { String value = ISO8601Utils.format(date); toAppendTo.append(value); return toAppendTo; }
/** * Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone) * * @param date the date to format * @param millis true to include millis precision otherwise false * @return the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z' */ public static String format(Date date, boolean millis) { return format(date, millis, TIMEZONE_GMT); }
/** * Format a date into 'yyyy-MM-ddThh:mm:ssZ' (GMT timezone, no milliseconds precision) * * @param date the date to format * @return the date formatted as 'yyyy-MM-ddThh:mm:ssZ' */ public static String format(Date date) { return format(date, false, TIMEZONE_GMT); }
@Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { String value = ISO8601Utils.format(date); toAppendTo.append(value); return toAppendTo; }