Example usage for java.time LocalDateTime get

List of usage examples for java.time LocalDateTime get

Introduction

In this page you can find the example usage for java.time LocalDateTime get.

Prototype

@Override
public int get(TemporalField field) 

Source Link

Document

Gets the value of the specified field from this date-time as an int .

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime now = LocalDateTime.now();
    System.out.println(now.get(ChronoField.YEAR));
    System.out.println(now.get(ChronoField.MONTH_OF_YEAR));
    System.out.println(now.get(ChronoField.DAY_OF_MONTH));
    System.out.println(now.get(ChronoField.HOUR_OF_DAY));
    System.out.println(now.get(ChronoField.HOUR_OF_AMPM));
    System.out.println(now.get(ChronoField.AMPM_OF_DAY));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);

    System.out.println(a.get(ChronoField.DAY_OF_WEEK));
}

From source file:com.thinkbiganalytics.integration.IntegrationTestBase.java

private ServiceLevelAgreementGroup createFeedProcessingDeadlineSla(String feedName, String feedId,
        LocalDateTime deadline, String noLaterThanHours) {
    int hourOfDay = deadline.get(ChronoField.HOUR_OF_DAY);
    int minuteOfHour = deadline.get(ChronoField.MINUTE_OF_HOUR);
    String cronExpression = String.format("0 %s %s 1/1 * ? *", minuteOfHour, hourOfDay);

    ServiceLevelAgreementGroup sla = new ServiceLevelAgreementGroup();
    String time = deadline.format(DateTimeFormatter.ofPattern("HH:mm"));
    sla.setName("Before " + time + " (cron: " + cronExpression + ")");
    sla.setDescription("The feed should complete before given date and time");
    List<ServiceLevelAgreementRule> rules = new ArrayList<>();
    ServiceLevelAgreementRule rule = new ServiceLevelAgreementRule();
    rule.setName("Feed Processing deadline");
    rule.setDisplayName("Feed Processing deadline");
    rule.setDescription("Ensure a Feed processes data by a specified time");
    rule.setObjectClassType("com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric");
    rule.setObjectShortClassType("FeedOnTimeArrivalMetric");
    rule.setCondition(ObligationGroup.Condition.REQUIRED);

    rule.setProperties(newFieldRuleProperties(newFieldRuleProperty("FeedName", "feedName", feedName),
            newFieldRuleProperty("ExpectedDeliveryTime", "cronString", cronExpression),
            newFieldRuleProperty("NoLaterThanTime", "lateTime", noLaterThanHours),
            newFieldRuleProperty("NoLaterThanUnits", "lateUnits", "hrs")));

    rules.add(rule);/*from  w  w  w. ja va 2  s .co  m*/
    sla.setRules(rules);

    Response response = given(ServiceLevelAgreementRestController.V1_FEEDMGR_SLA).body(sla).when()
            .post(String.format("feed/%s", feedId));

    response.then().statusCode(HTTP_OK);

    return response.as(ServiceLevelAgreementGroup.class);
}

From source file:onl.area51.gfs.grib2.job.GribRetriever.java

/**
 * Convert a {@link LocalDateTime} to a GFS run time. Specifically this is the date and hour of the day restricted to 0, 7, 12 or 18 hours.
 * <p>//from www.j av a  2 s  .  com
 * @param date date
 * <p>
 * @return date modified to the nearest GFS run (earlier than date) or null if date was null
 */
public static LocalDateTime toGFSRunTime(LocalDateTime date) {
    if (date == null) {
        return null;
    }

    LocalDateTime dateTime = date.truncatedTo(ChronoUnit.HOURS);

    // Only allow hours 0, 6, 12 & 18
    int h = dateTime.get(ChronoField.HOUR_OF_DAY);
    if (h % 6 == 0) {
        return dateTime;
    }

    return dateTime.withHour((h / 6) * 6);
}