Example usage for java.time Period parse

List of usage examples for java.time Period parse

Introduction

In this page you can find the example usage for java.time Period parse.

Prototype

public static Period parse(CharSequence text) 

Source Link

Document

Obtains a Period from a text string such as PnYnMnD .

Usage

From source file:Main.java

public static void main(String[] args) {

    Period p = Period.parse("P5D");

    System.out.println(p.toString());

}

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Period.parse("P3Y6M4D"));
    System.out.println(Duration.parse("PT12H30M5S"));
}

From source file:io.pivotal.strepsirrhini.chaosloris.PeriodConverter.java

@Override
public Period convert(String source) {
    return Period.parse(source);
}

From source file:io.pivotal.strepsirrhini.chaosloris.reaper.EventReaper.java

@Autowired
EventReaper(EventRepository eventRepository, @Value("${loris.reaper.history}") String period) {
    this.eventRepository = eventRepository;
    this.period = Period.parse(period);
}

From source file:org.edgexfoundry.scheduling.ScheduleContext.java

private void parsePeriodAndDuration(String frequency) {

    int periodStart = frequency.indexOf('P');
    int timeStart = frequency.indexOf('T');
    String freq = frequency;//from w  w  w .j  av a  2 s. c  om

    this.period = Period.ZERO;
    this.duration = Duration.ZERO;

    // Parse out the period (date)
    try {
        // If there is a duration 'T', remove it
        if (timeStart != -1)
            freq = frequency.substring(periodStart, timeStart);
        this.period = Period.parse(freq);
    } catch (IndexOutOfBoundsException | DateTimeParseException e) {
        logger.error("parsePeriodAndDuration() failed to parse period from '" + freq + "'");
    }

    // Parse out the duration (time)
    try {
        // Make sure there is both a 'P' and 'T'
        if (periodStart != -1 && timeStart != -1) {
            freq = frequency.substring(timeStart, frequency.length());
            this.duration = Duration.parse("P" + freq);
        }
    } catch (IndexOutOfBoundsException | DateTimeParseException e) {
        logger.error("parsePeriodAndDuration() failed to parse duration from 'P" + freq + "'");
    }
}