org.joda.time.format.DateTimeFormatter.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.joda.time.format.DateTimeFormatter.<init>()方法的一些代码示例,展示了DateTimeFormatter.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.<init>()方法的具体详情如下:
包路径:org.joda.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:<init>

DateTimeFormatter.<init>介绍

[英]Creates a new formatter, however you will normally use the factory or the builder.
[中]创建一个新的格式化程序,但是您通常会使用工厂或生成器。

代码示例

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

return this;
return new DateTimeFormatter(iPrinter, iParser, iLocale,
    iOffsetParsed, iChrono, iZone, pivotYear, iDefaultYear);

代码示例来源:origin: JodaOrg/joda-time

return this;
return new DateTimeFormatter(iPrinter, iParser, iLocale,
    iOffsetParsed, iChrono, iZone, pivotYear, iDefaultYear);

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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");
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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");
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

相关文章