本文整理汇总了Java中java.time.Period.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Period.parse方法的具体用法?Java Period.parse怎么用?Java Period.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Period
的用法示例。
在下文中一共展示了Period.parse方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanupAuditData
import java.time.Period; //导入方法依赖的package包/类
protected void cleanupAuditData(final String auditApplicationName, final JobExecutionContext context)
{
final AuditService auditService = JobUtilities.getJobDataValue(context, "auditService", AuditService.class);
final String cutOffPeriodStr = JobUtilities.getJobDataValue(context, "cutOffPeriod", String.class);
final String timezoneStr = JobUtilities.getJobDataValue(context, "timezone", String.class, false);
final Period cutOffPeriod = Period.parse(cutOffPeriodStr);
final ZoneId zone = ZoneId.of(timezoneStr != null ? timezoneStr : "Z");
final ZonedDateTime now = LocalDateTime.now(ZoneId.of("Z")).atZone(zone);
final ZonedDateTime cutOffDate = now.minus(cutOffPeriod);
final long epochSecond = cutOffDate.toEpochSecond();
LOGGER.debug("Clearing all audit entries of application {} until {}", auditApplicationName, cutOffDate);
auditService.clearAudit(auditApplicationName, null, Long.valueOf(epochSecond));
}
示例2: stringToPeriod
import java.time.Period; //导入方法依赖的package包/类
public Period stringToPeriod(String in) {
if (in == null || in.isEmpty()) {
return Period.ofDays(1);
} else {
return Period.parse(in);
}
}
示例3: deserialize
import java.time.Period; //导入方法依赖的package包/类
@Override
public void deserialize(ConfigurationSection config) {
ISerializable.deserialize(config, this);
this.duration = Duration.parse(config.getString("duration"));
this.resetPeriod = Period.parse(config.getString("resetPeriod"));
this.periodCountingBase = ZonedDateTime.parse(config.getString("periodCountingBase"));
this.creationTime = Instant.parse(config.getString("creationTime"));
this.lastTimerCallback = Instant.parse(config.getString("lastTimerCallback"));
this.lastResetCallback = Instant.parse(config.getString("lastResetCallback"));
this.lastCheckpoint = Instant.parse(config.getString("lastCheckpoint"));
this.timeElapsed = Duration.parse(config.getString("timeElapsed"));
}
示例4: deserialize
import java.time.Period; //导入方法依赖的package包/类
@Override
public void deserialize(ConfigurationSection config) {
ISerializable.deserialize(config, this);
this.duration = Duration.parse(config.getString("duration"));
this.resetPeriod = Period.parse(config.getString("resetPeriod"));
this.periodCountingBase = ZonedDateTime.parse(config.getString("periodCountingBase"));
}
示例5: deserialze
import java.time.Period; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 4) {
String text = lexer.stringVal();
lexer.nextToken();
if (type == LocalDateTime.class) {
return LocalDateTime.parse(text);
}
if (type == LocalDate.class) {
return LocalDate.parse(text);
}
if (type == LocalTime.class) {
return LocalTime.parse(text);
}
if (type == ZonedDateTime.class) {
return ZonedDateTime.parse(text);
}
if (type == OffsetDateTime.class) {
return OffsetDateTime.parse(text);
}
if (type == OffsetTime.class) {
return OffsetTime.parse(text);
}
if (type == ZoneId.class) {
return ZoneId.of(text);
}
if (type == Period.class) {
return Period.parse(text);
}
if (type == Duration.class) {
return Duration.parse(text);
}
if (type == Instant.class) {
return Instant.parse(text);
}
return null;
}
throw new UnsupportedOperationException();
}
示例6: factory_parse_minus
import java.time.Period; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse_minus(String text, Period expected) {
Period p = null;
try {
p = Period.parse("-" + text);
} catch (DateTimeParseException ex) {
assertEquals(expected.getYears() == Integer.MIN_VALUE ||
expected.getMonths() == Integer.MIN_VALUE ||
expected.getDays() == Integer.MIN_VALUE, true);
return;
}
// not inside try/catch or it breaks test
assertEquals(p, expected.negated());
}
示例7: factory_parseFailures
import java.time.Period; //导入方法依赖的package包/类
@Test(dataProvider="parseFailure", expectedExceptions=DateTimeParseException.class)
public void factory_parseFailures(String text) {
try {
Period.parse(text);
} catch (DateTimeParseException ex) {
assertEquals(ex.getParsedString(), text);
throw ex;
}
}
示例8: withChunkPeriod
import java.time.Period; //导入方法依赖的package包/类
public T withChunkPeriod(String chunkPeriod) {
this.chunkPeriod = Period.parse(chunkPeriod);
return (T) this;
}
示例9: main
import java.time.Period; //导入方法依赖的package包/类
public static void main(String[] args) {
Period period = Period.of(1, 2, 7);
Period period2 = Period.ofYears(2);
Period period3 = Period.ofMonths(5);
Period period4 = Period.ofWeeks(10);
Period period5 = Period.ofDays(15);
Period period6 = Period.ofDays(15);
Period p5Yrs1 = Period.parse("P5y");
Period p5Yrs2 = Period.parse("p5y");
Period p5Yrs3 = Period.parse("P5Y");
Period p5Yrs4 = Period.parse("+P5Y");
Period p5Yrs5 = Period.parse("P+5Y");
Period p5Yrs6 = Period.parse("-P-5Y");
System.out.printf("%s : %s", p5Yrs1, p5Yrs2);
System.out.println();
System.out.printf("-P-5Y: %s", p5Yrs6);
System.out.println();
Period p5Yrs7 = Period.parse("P5y1m2d");
Period p5Yrs8 = Period.parse("p9m");
Period p5Yrs9 = Period.parse("P60d");
// For the string form PnW, the count of weeks is multiplied by 7 to
// get the number of days
Period p5Yrs10 = Period.parse("-P5Y5W");
System.out.printf("p5Yrs7: %s, p5Yrs8: %s, p5Yrs9: %s, p5Yrs10: %s",
p5Yrs7,
p5Yrs8,
p5Yrs9,
p5Yrs10);
System.out.println();
// static method between
LocalDate carnivalStart = LocalDate.of(2050, 12, 31);
LocalDate carnivalEnd = LocalDate.of(2051, 1, 2);
// period = endDate - startDate
Period periodBetween = Period.between(carnivalEnd, carnivalStart);
System.out.println(periodBetween );
}
示例10: factory_parse
import java.time.Period; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse(String text, Period expected) {
Period p = Period.parse(text);
assertEquals(p, expected);
}
示例11: factory_parse_plus
import java.time.Period; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse_plus(String text, Period expected) {
Period p = Period.parse("+" + text);
assertEquals(p, expected);
}
示例12: factory_parse_lowerCase
import java.time.Period; //导入方法依赖的package包/类
@Test(dataProvider="parseSuccess")
public void factory_parse_lowerCase(String text, Period expected) {
Period p = Period.parse(text.toLowerCase(Locale.ENGLISH));
assertEquals(p, expected);
}
示例13: factory_parse_null
import java.time.Period; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_null() {
Period.parse(null);
}