本文整理匯總了Java中java.time.format.DateTimeFormatterBuilder.appendPattern方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeFormatterBuilder.appendPattern方法的具體用法?Java DateTimeFormatterBuilder.appendPattern怎麽用?Java DateTimeFormatterBuilder.appendPattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.format.DateTimeFormatterBuilder
的用法示例。
在下文中一共展示了DateTimeFormatterBuilder.appendPattern方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_parseAdjacent
import java.time.format.DateTimeFormatterBuilder; //導入方法依賴的package包/類
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
ParsePosition ppos = new ParsePosition(0);
builder = new DateTimeFormatterBuilder();
setStrict(strict);
builder.appendPattern(pattern);
DateTimeFormatter dtf = builder.toFormatter();
TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
} else {
assertEquals(ppos.getIndex(), parseLen, "parse position");
assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
}
}
示例2: test_printAdjacent
import java.time.format.DateTimeFormatterBuilder; //導入方法依賴的package包/類
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
builder = new DateTimeFormatterBuilder();
builder.appendPattern(pattern);
DateTimeFormatter dtf = builder.toFormatter();
LocalDate ld = LocalDate.of(year, month, day);
String actual = dtf.format(ld);
assertEquals(actual, text, "formatter output: " + dtf);
}