當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTimeFormatter.ISO_DATE屬性代碼示例

本文整理匯總了Java中java.time.format.DateTimeFormatter.ISO_DATE屬性的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeFormatter.ISO_DATE屬性的具體用法?Java DateTimeFormatter.ISO_DATE怎麽用?Java DateTimeFormatter.ISO_DATE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.time.format.DateTimeFormatter的用法示例。


在下文中一共展示了DateTimeFormatter.ISO_DATE屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

public static void main(String[] args) {
    DateTimeFormatter formatter1 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
    DateTimeFormatter formatter2 = DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL);
    DateTimeFormatter formatter3 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
    DateTimeFormatter formatter4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT);

    DateTimeFormatter formatter5 = DateTimeFormatter.BASIC_ISO_DATE;

    // 2057-08-11
    DateTimeFormatter isoLocalDate = DateTimeFormatter.ISO_LOCAL_DATE;
    DateTimeFormatter isoDate = DateTimeFormatter.ISO_DATE;

    // 14:30:15.312
    DateTimeFormatter isoTime = DateTimeFormatter.ISO_TIME;
    DateTimeFormatter isoLocalTime = DateTimeFormatter.ISO_LOCAL_TIME;

    // 2050-08-11T14:30:15.312
    DateTimeFormatter isoDateTime = DateTimeFormatter.ISO_DATE_TIME;
    DateTimeFormatter isoLocaDateTime = DateTimeFormatter.ISO_LOCAL_DATE_TIME;


}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:22,代碼來源:Main.java

示例2: createDateTimeFormatter

/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormatter.ofPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE;
				break;
			case TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_TIME;
				break;
			case DATE_TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (this.dateStyle != null && this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
	}
	else if (this.dateStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
	}
	else if (this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:DateTimeFormatterFactory.java

示例3: test_parse_CharSequence_ParsePosition_resolved

@Test
public void test_parse_CharSequence_ParsePosition_resolved() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos);
    assertEquals(pos.getIndex(), 13);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(YEAR), true);
    assertEquals(result.isSupported(MONTH_OF_YEAR), true);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
    assertEquals(result.getLong(YEAR), 2012L);
    assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:TCKDateTimeFormatter.java

示例4: testFormat4System

/**
 * 使用係統自帶的格式化格式
 */
@Test
public void testFormat4System() {
    // 使用係統自帶的格式化
    DateTimeFormatter isoDateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
    DateTimeFormatter isoDateFormat = DateTimeFormatter.ISO_DATE;

    // 獲取當前時間
    LocalDateTime now = LocalDateTime.now();

    // 格式化1
    String dateTimeFormat = now.format(isoDateTimeFormatter);
    System.out.println(dateTimeFormat);

    // 格式化2
    String dateFormat = now.format(isoDateFormat);
    System.out.println(dateFormat);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:20,代碼來源:DateTimeFormatterDemo.java

示例5: test_parse_CharSequence_resolved

@Test
public void test_parse_CharSequence_resolved() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    TemporalAccessor result = test.parse("2012-06-30");
    assertEquals(result.isSupported(YEAR), true);
    assertEquals(result.isSupported(MONTH_OF_YEAR), true);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
    assertEquals(result.getLong(YEAR), 2012L);
    assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:TCKDateTimeFormatter.java

示例6: test_parse_CharSequence_ParsePosition_parseError

@Test(expectedExceptions=DateTimeParseException.class)
public void test_parse_CharSequence_ParsePosition_parseError() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    try {
        test.parse("XXX2012XXX", pos);
        fail();
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getErrorIndex(), 7);
        throw ex;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKDateTimeFormatter.java

示例7: main

public static void main(String[] args) {
    DateTimeFormatter d1 = DateTimeFormatter.ISO_DATE;
    LocalDate ld = LocalDate.from(d1.parse("2020-12-12"));
    System.out.println(ld );
}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:5,代碼來源:Main.java

示例8: test_parse_CharSequence_ParsePosition_indexTooBig

@Test(expectedExceptions=IndexOutOfBoundsException.class)
public void test_parse_CharSequence_ParsePosition_indexTooBig() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    test.parse("Text", new ParsePosition(5));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKDateTimeFormatter.java


注:本文中的java.time.format.DateTimeFormatter.ISO_DATE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。