/** * Returns a new formatter that will create a datetime with a time zone * equal to that of the offset of the parsed string. * <p> * After calling this method, a string '2004-06-09T10:20:30-08:00' will * create a datetime with a zone of -08:00 (a fixed zone, with no daylight * savings rules). If the parsed string represents a local time (no zone * offset) the parsed datetime will be in the default zone. * <p> * Calling this method sets the override zone to null. * Calling the override zone method sets this flag off. * * @return the new formatter */ public DateTimeFormatter withOffsetParsed() { if (iOffsetParsed == true) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, true, iChrono, null, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified default year. * <p> * The default year is used when parsing in the case where there is a * month or a day but not a year. Specifically, it is used if there is * a field parsed with a duration between the length of a month and the * length of a day inclusive. * <p> * This value is typically used to move the year from 1970 to a leap year * to enable February 29th to be parsed. * Unless customised, the year 2000 is used. * <p> * This setting has no effect when printing. * * @param defaultYear the default year to use * @return the new formatter, not null * @since 2.0 */ public DateTimeFormatter withDefaultYear(int defaultYear) { return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, iChrono, iZone, iPivotYear, defaultYear); }
/** * Returns a new formatter that will create a datetime with a time zone * equal to that of the offset of the parsed string. * <p> * After calling this method, a string '2004-06-09T10:20:30-08:00' will * create a datetime with a zone of -08:00 (a fixed zone, with no daylight * savings rules). If the parsed string represents a local time (no zone * offset) the parsed datetime will be in the default zone. * <p> * Calling this method sets the override zone to null. * Calling the override zone method sets this flag off. * * @return the new formatter */ public DateTimeFormatter withOffsetParsed() { if (iOffsetParsed == true) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, true, iChrono, null, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified chronology in * preference to that of the printed object, or ISO on a parse. * <p> * When printing, this chronology will be used in preference to the chronology * from the datetime that would otherwise be used. * <p> * When parsing, this chronology will be set on the parsed datetime. * <p> * A null chronology means no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param chrono the chronology to use as an override * @return the new formatter */ public DateTimeFormatter withChronology(Chronology chrono) { if (iChrono == chrono) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, chrono, iZone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified zone in preference * to the zone of the printed object, or default zone on a parse. * <p> * When printing, this zone will be used in preference to the zone * from the datetime that would otherwise be used. * <p> * When parsing, this zone will be set on the parsed datetime. * <p> * A null zone means of no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param zone the zone to use as an override * @return the new formatter */ public DateTimeFormatter withZone(DateTimeZone zone) { if (iZone == zone) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, false, iChrono, zone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified default year. * <p> * The default year is used when parsing in the case where there is a * month or a day but not a year. Specifically, it is used if there is * a field parsed with a duration between the length of a month and the * length of a day inclusive. * <p> * This value is typically used to move the year from 1970 to a leap year * to enable February 29th to be parsed. * Unless customised, the year 2000 is used. * <p> * This setting has no effect when printing. * * @param defaultYear the default year to use * @return the new formatter, not null * @since 2.0 */ public DateTimeFormatter withDefaultYear(int defaultYear) { return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, iChrono, iZone, iPivotYear, defaultYear); }
/** * Returns a new formatter that will use the specified chronology in * preference to that of the printed object, or ISO on a parse. * <p> * When printing, this chronology will be used in preference to the chronology * from the datetime that would otherwise be used. * <p> * When parsing, this chronology will be set on the parsed datetime. * <p> * A null chronology means no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param chrono the chronology to use as an override * @return the new formatter */ public DateTimeFormatter withChronology(Chronology chrono) { if (iChrono == chrono) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, chrono, iZone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified zone in preference * to the zone of the printed object, or default zone on a parse. * <p> * When printing, this zone will be used in preference to the zone * from the datetime that would otherwise be used. * <p> * When parsing, this zone will be set on the parsed datetime. * <p> * A null zone means of no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param zone the zone to use as an override * @return the new formatter */ public DateTimeFormatter withZone(DateTimeZone zone) { if (iZone == zone) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, false, iChrono, zone, iPivotYear, iDefaultYear); }
return this; return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, iChrono, iZone, pivotYear, iDefaultYear);
return this; return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, iChrono, iZone, pivotYear, iDefaultYear);
/** * Creates a formatter for the specified style. * * @param dateStyle the date style * @param timeStyle the time style * @return the formatter */ private static DateTimeFormatter createDateTimeFormatter(int dateStyle, int timeStyle){ int type = DATETIME; if (dateStyle == NONE) { type = TIME; } else if (timeStyle == NONE) { type = DATE; } StyleFormatter llf = new StyleFormatter(dateStyle, timeStyle, type); return new DateTimeFormatter(llf, llf); }
/** * Creates a formatter for the specified style. * * @param dateStyle the date style * @param timeStyle the time style * @return the formatter */ private static DateTimeFormatter createDateTimeFormatter(int dateStyle, int timeStyle){ int type = DATETIME; if (dateStyle == NONE) { type = TIME; } else if (timeStyle == NONE) { type = DATE; } StyleFormatter llf = new StyleFormatter(dateStyle, timeStyle, type); return new DateTimeFormatter(llf, llf); }
/** * Returns a new formatter with a different locale that will be used * for printing and parsing. * <p> * A DateTimeFormatter is immutable, so a new instance is returned, * and the original is unaltered and still usable. * * @param locale the locale to use; if null, formatter uses default locale * at invocation time * @return the new formatter */ public DateTimeFormatter withLocale(Locale locale) { if (locale == getLocale() || (locale != null && locale.equals(getLocale()))) { return this; } return new DateTimeFormatter(iPrinter, iParser, locale, iOffsetParsed, iChrono, iZone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter with a different locale that will be used * for printing and parsing. * <p> * A DateTimeFormatter is immutable, so a new instance is returned, * and the original is unaltered and still usable. * * @param locale the locale to use; if null, formatter uses default locale * at invocation time * @return the new formatter */ public DateTimeFormatter withLocale(Locale locale) { if (locale == getLocale() || (locale != null && locale.equals(getLocale()))) { return this; } return new DateTimeFormatter(iPrinter, iParser, locale, iOffsetParsed, iChrono, iZone, iPivotYear, iDefaultYear); }
/** * Constructs a DateTimeFormatter using all the appended elements. * <p> * This is the main method used by applications at the end of the build * process to create a usable formatter. * <p> * Subsequent changes to this builder do not affect the returned formatter. * <p> * The returned formatter may not support both printing and parsing. * The methods {@link DateTimeFormatter#isPrinter()} and * {@link DateTimeFormatter#isParser()} will help you determine the state * of the formatter. * * @throws UnsupportedOperationException if neither printing nor parsing is supported */ public DateTimeFormatter toFormatter() { Object f = getFormatter(); InternalPrinter printer = null; if (isPrinter(f)) { printer = (InternalPrinter) f; } InternalParser parser = null; if (isParser(f)) { parser = (InternalParser) f; } if (printer != null || parser != null) { return new DateTimeFormatter(printer, parser); } throw new UnsupportedOperationException("Both printing and parsing not supported"); }
/** * Constructs a DateTimeFormatter using all the appended elements. * <p> * This is the main method used by applications at the end of the build * process to create a usable formatter. * <p> * Subsequent changes to this builder do not affect the returned formatter. * <p> * The returned formatter may not support both printing and parsing. * The methods {@link DateTimeFormatter#isPrinter()} and * {@link DateTimeFormatter#isParser()} will help you determine the state * of the formatter. * * @throws UnsupportedOperationException if neither printing nor parsing is supported */ public DateTimeFormatter toFormatter() { Object f = getFormatter(); InternalPrinter printer = null; if (isPrinter(f)) { printer = (InternalPrinter) f; } InternalParser parser = null; if (isParser(f)) { parser = (InternalParser) f; } if (printer != null || parser != null) { return new DateTimeFormatter(printer, parser); } throw new UnsupportedOperationException("Both printing and parsing not supported"); }
/** * Returns a new formatter that will create a datetime with a time zone * equal to that of the offset of the parsed string. * <p> * After calling this method, a string '2004-06-09T10:20:30-08:00' will * create a datetime with a zone of -08:00 (a fixed zone, with no daylight * savings rules). If the parsed string represents a local time (no zone * offset) the parsed datetime will be in the default zone. * <p> * Calling this method sets the override zone to null. * Calling the override zone method sets this flag off. * * @return the new formatter */ public DateTimeFormatter withOffsetParsed() { if (iOffsetParsed == true) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, true, iChrono, null, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified chronology in * preference to that of the printed object, or ISO on a parse. * <p> * When printing, this chronolgy will be used in preference to the chronology * from the datetime that would otherwise be used. * <p> * When parsing, this chronology will be set on the parsed datetime. * <p> * A null chronology means no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param chrono the chronology to use as an override * @return the new formatter */ public DateTimeFormatter withChronology(Chronology chrono) { if (iChrono == chrono) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, iOffsetParsed, chrono, iZone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter that will use the specified zone in preference * to the zone of the printed object, or default zone on a parse. * <p> * When printing, this zone will be used in preference to the zone * from the datetime that would otherwise be used. * <p> * When parsing, this zone will be set on the parsed datetime. * <p> * A null zone means of no-override. * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @param zone the zone to use as an override * @return the new formatter */ public DateTimeFormatter withZone(DateTimeZone zone) { if (iZone == zone) { return this; } return new DateTimeFormatter(iPrinter, iParser, iLocale, false, iChrono, zone, iPivotYear, iDefaultYear); }
/** * Returns a new formatter with a different locale that will be used * for printing and parsing. * <p> * A DateTimeFormatter is immutable, so a new instance is returned, * and the original is unaltered and still usable. * * @param locale the locale to use; if null, formatter uses default locale * at invocation time * @return the new formatter */ public DateTimeFormatter withLocale(Locale locale) { if (locale == getLocale() || (locale != null && locale.equals(getLocale()))) { return this; } return new DateTimeFormatter(iPrinter, iParser, locale, iOffsetParsed, iChrono, iZone, iPivotYear, iDefaultYear); }