当前位置: 首页>>代码示例>>Java>>正文


Java Period.parse方法代码示例

本文整理汇总了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));
}
 
开发者ID:Acosix,项目名称:alfresco-audit,代码行数:17,代码来源:AuditApplicationCleanupJob.java

示例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);
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:8,代码来源:TimeMappingUtil.java

示例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"));
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:14,代码来源:TimerPersistData.java

示例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"));
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:8,代码来源:TimerData.java

示例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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:40,代码来源:Jdk8DateCodec.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:TCKPeriod.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKPeriod.java

示例8: withChunkPeriod

import java.time.Period; //导入方法依赖的package包/类
public T withChunkPeriod(String chunkPeriod) {
    this.chunkPeriod = Period.parse(chunkPeriod);
    return (T) this;
}
 
开发者ID:levin81,项目名称:daelic,代码行数:5,代码来源:Context.java

示例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 );

}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:46,代码来源:Main.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKPeriod.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKPeriod.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKPeriod.java

示例13: factory_parse_null

import java.time.Period; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_null() {
    Period.parse(null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKPeriod.java


注:本文中的java.time.Period.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。