java.time.YearMonth.format()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(146)

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

YearMonth.format介绍

[英]Outputs this year-month as a String using the formatter.

This year-month will be passed to the formatter DateTimeFormatter#format(TemporalAccessor).
[中]使用格式化程序以字符串形式输出今年的月份。
今年的月份将传递给格式化程序DateTimeFormatter#format(TemporalAccessor)。

代码示例

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

  1. @Override
  2. public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
  3. {
  4. if (useTimestamp(provider)) {
  5. g.writeStartArray();
  6. _serializeAsArrayContents(value, g, provider);
  7. g.writeEndArray();
  8. return;
  9. }
  10. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  11. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
  3. {
  4. if (useTimestamp(provider)) {
  5. g.writeStartArray();
  6. _serializeAsArrayContents(value, g, provider);
  7. g.writeEndArray();
  8. return;
  9. }
  10. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  11. }

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

  1. @Override
  2. public void serializeWithType(YearMonth value, JsonGenerator g,
  3. SerializerProvider provider, TypeSerializer typeSer) throws IOException
  4. {
  5. WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
  6. typeSer.typeId(value, serializationShape(provider)));
  7. // need to write out to avoid double-writing array markers
  8. if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
  9. _serializeAsArrayContents(value, g, provider);
  10. } else {
  11. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  12. }
  13. typeSer.writeTypeSuffix(g, typeIdDef);
  14. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void serializeWithType(YearMonth value, JsonGenerator g,
  3. SerializerProvider provider, TypeSerializer typeSer) throws IOException
  4. {
  5. WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
  6. typeSer.typeId(value, serializationShape(provider)));
  7. // need to write out to avoid double-writing array markers
  8. if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
  9. _serializeAsArrayContents(value, g, provider);
  10. } else {
  11. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  12. }
  13. typeSer.writeTypeSuffix(g, typeIdDef);
  14. }

代码示例来源:origin: stackoverflow.com

  1. YearMonth source = YearMonth.now();
  2. DateTimeFormatter english = DateTimeFormatter.ofPattern("MMMM, yyyy", Locale.ENGLISH);
  3. DateTimeFormatter german = DateTimeFormatter.ofPattern("MMMM yyyy", Locale.GERMAN);
  4. System.out.println(source.format(english));
  5. System.out.println(source.format(german));

代码示例来源:origin: br.com.jarch/jarch-jsf

  1. @Override
  2. public String getAsString(FacesContext context, UIComponent component, Object value) {
  3. if (value == null) {
  4. return null;
  5. }
  6. if (value.toString().isEmpty()) {
  7. return "";
  8. }
  9. YearMonth yearMonth = (YearMonth) value;
  10. return yearMonth.format(ofPattern("MM/yyyy"));
  11. }
  12. }

代码示例来源:origin: stackoverflow.com

  1. YearMonth thisMonth = YearMonth.now();
  2. YearMonth lastMonth = thisMonth.minusMonths(1);
  3. YearMonth twoMonthsAgo = thisMonth.minusMonths(2);
  4. DateTimeFormatter monthYearFormatter = DateTimeFormatter.ofPattern("MMMM yyyy");
  5. System.out.printf("Today: %s\n", thisMonth.format(monthYearFormatter));
  6. System.out.printf("Last Month: %s\n", lastMonth.format(monthYearFormatter));
  7. System.out.printf("Two Months Ago: %s\n", twoMonthsAgo.format(monthYearFormatter));

代码示例来源:origin: OpenGamma/Strata

  1. @ImmutablePreBuild
  2. private static void preBuild(Builder builder) {
  3. if (builder.label == null && builder.yearMonth != null) {
  4. builder.label = builder.yearMonth.format(FORMATTER);
  5. }
  6. }

代码示例来源:origin: OpenGamma/Strata

  1. /**
  2. * Summarizes this ETD future into string form.
  3. *
  4. * @return the summary description
  5. */
  6. public String summaryDescription() {
  7. return variant.getCode() + expiry.format(YM_FORMAT);
  8. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueInsertTest() {
  3. return YearMonth.now().format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: org.opensingular/form-core

  1. @Override
  2. protected String toStringPersistence(YearMonth originalValue) {
  3. return originalValue == null ? null : originalValue.format(formatter());
  4. }

代码示例来源:origin: stackoverflow.com

  1. public static void main(String[] args) {
  2. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM-yyyy", Locale.ENGLISH);
  3. YearMonth startDate = YearMonth.parse("Jan-2015", formatter);
  4. YearMonth endDate = YearMonth.parse("Apr-2015", formatter);
  5. while(startDate.isBefore(endDate)) {
  6. System.out.println(startDate.format(formatter));
  7. startDate = startDate.plusMonths(1);
  8. }
  9. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueChangeTest() {
  3. return YearMonth.now().minusMonths(2).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: stackoverflow.com

  1. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu.MM");
  2. YearMonth date = YearMonth.parse("2010.01", formatter);
  3. YearMonth end = YearMonth.parse("2010.05", formatter);
  4. while (!date.isAfter(end)) {
  5. System.out.println(date.format(formatter));
  6. date = date.plusMonths(1);
  7. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueCloneTest() {
  3. return YearMonth.now().minusMonths(1).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: amedia/freemarker-java-8

  1. @Override
  2. public Object exec(List list) throws TemplateModelException {
  3. return getObject().format(createDateTimeFormatter(list, 0, "yyyy-MM"));
  4. }
  5. }

代码示例来源:origin: OpenGamma/Strata

  1. /**
  2. * Obtains an instance using the year-month.
  3. *
  4. * @param date the date associated with the parameter
  5. * @param yearMonth the year-month of the curve node
  6. * @return the parameter metadata based on the year-month
  7. */
  8. public static YearMonthDateParameterMetadata of(LocalDate date, YearMonth yearMonth) {
  9. ArgChecker.notNull(date, "date");
  10. ArgChecker.notNull(yearMonth, "yearMonth");
  11. return new YearMonthDateParameterMetadata(date, yearMonth, yearMonth.format(FORMATTER));
  12. }

代码示例来源:origin: com.facebook.presto/presto-jdbc

  1. @Override
  2. public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
  3. {
  4. if (useTimestamp(provider)) {
  5. g.writeStartArray();
  6. _serializeAsArrayContents(value, g, provider);
  7. g.writeEndArray();
  8. return;
  9. }
  10. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  11. }

代码示例来源:origin: io.prestosql/presto-jdbc

  1. @Override
  2. public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
  3. {
  4. if (useTimestamp(provider)) {
  5. g.writeStartArray();
  6. _serializeAsArrayContents(value, g, provider);
  7. g.writeEndArray();
  8. return;
  9. }
  10. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  11. }

代码示例来源:origin: prestosql/presto

  1. @Override
  2. public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
  3. {
  4. if (useTimestamp(provider)) {
  5. g.writeStartArray();
  6. _serializeAsArrayContents(value, g, provider);
  7. g.writeEndArray();
  8. return;
  9. }
  10. g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
  11. }

相关文章