Example usage for java.time ZonedDateTime getMonthValue

List of usage examples for java.time ZonedDateTime getMonthValue

Introduction

In this page you can find the example usage for java.time ZonedDateTime getMonthValue.

Prototype

public int getMonthValue() 

Source Link

Document

Gets the month-of-year field from 1 to 12.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();

    System.out.println(dateTime.getMonthValue());
}

From source file:org.caratarse.auth.model.dao.UserAttributesTest.java

@Test
public void birthdateUserAttribute() {
    User user = retrieveUserWithAttributes();
    Attribute attribute = user.getUserAttributes().get("birthdate");
    assertTrue(attribute instanceof DateAttribute);
    assertThat(attribute.getName(), is("birthdate"));
    final Date value = new Date(((Date) attribute.getValue()).getTime());
    ZonedDateTime v = value.toInstant().atZone(ZoneId.systemDefault());
    assertThat(v.getDayOfMonth(), is(5));
    assertThat(v.getMonthValue(), is(7));
    assertThat(v.getYear(), is(1980));//  w  w w  . j  av a  2  s . com
}

From source file:org.caratarse.auth.model.dao.UserAttributesTest.java

@Test
public void lastUserAttribute() {
    User user = retrieveUserWithAttributes();
    Attribute attribute = user.getUserAttributes().get("last");
    assertTrue(attribute instanceof DateTimeAttribute);
    assertThat(attribute.getName(), is("last"));
    final Date value = new Date(((Date) attribute.getValue()).getTime());
    ZonedDateTime v = value.toInstant().atZone(ZoneId.of("UTC"));
    assertThat(v.getDayOfMonth(), is(20));
    assertThat(v.getMonthValue(), is(11));
    assertThat(v.getYear(), is(2015));//from  ww  w.jav  a 2  s .c  o  m
    assertThat(v.getHour(), is(12));
    assertThat(v.getMinute(), is(11));
    assertThat(v.getSecond(), is(10));
    assertThat(v.getNano(), is(999000000));
}

From source file:org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest.java

/**
 * Gets a valid cron expression describing a schedule with a single
 * maintenance window, starting specified number of minutes after current
 * time.//  ww  w .  j  ava  2  s  . c  om
 *
 * @param minutesToAdd
 *            is the number of minutes after the current time
 *
 * @return {@link String} containing a valid cron expression.
 */
protected static String getTestSchedule(final int minutesToAdd) {
    ZonedDateTime currentTime = ZonedDateTime.now();
    currentTime = currentTime.plusMinutes(minutesToAdd);
    return String.format("%d %d %d %d %d ? %d", currentTime.getSecond(), currentTime.getMinute(),
            currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(),
            currentTime.getYear());
}

From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverterTest.java

@Test
public void fromStrings() {
    GlobalConverter converter = new ZonedDateTimeConverter(new MockConfiguration());
    ZonedDateTime value = (ZonedDateTime) converter.convertFromStrings(ZonedDateTime.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(value);//from   w w  w  .  j  a v a 2s.c om

    value = (ZonedDateTime) converter.convertFromStrings(Locale.class,
            MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy hh:mm:ss a Z"), "testExpr",
            ArrayUtils.toArray("07-08-2008 10:13:34 AM -0800"));
    assertEquals(value.getMonthValue(), 7);
    assertEquals(value.getDayOfMonth(), 8);
    assertEquals(value.getYear(), 2008);
    assertEquals(value.getHour(), 10);
    assertEquals(value.getMinute(), 13);
    assertEquals(value.getSecond(), 34);
    assertEquals(value.getZone(), ZoneOffset.ofHours(-8));

    try {
        converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr",
                ArrayUtils.toArray("07/08/2008"));
        fail("Should have failed");
    } catch (ConversionException e) {
        // Expected
    }
}

From source file:sorcer.file.ScratchDirManager.java

private boolean isCutoffTime(Path path, long cutOffTime) throws IOException {
    ZonedDateTime now = ZonedDateTime.now();
    BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
    ZonedDateTime created = ZonedDateTime.ofInstant(attrs.creationTime().toInstant(), now.getZone());

    created = created.withYear(now.getYear()).withMonth(now.getMonthValue());

    ZonedDateTime cutoff = created.plus(cutOffTime, MILLIS);

    log.info("Created {}", created);
    log.info("now     {}", now);
    log.info("cutoff  {}", cutoff);

    return now.isAfter(cutoff);
}

From source file:stroom.pipeline.server.writer.PathCreator.java

public static String replaceTimeVars(String path) {
    // Replace some of the path elements with system variables.
    final ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC);
    path = replace(path, "year", dateTime.getYear(), 4);
    path = replace(path, "month", dateTime.getMonthValue(), 2);
    path = replace(path, "day", dateTime.getDayOfMonth(), 2);
    path = replace(path, "hour", dateTime.getHour(), 2);
    path = replace(path, "minute", dateTime.getMinute(), 2);
    path = replace(path, "second", dateTime.getSecond(), 2);
    path = replace(path, "millis", dateTime.toInstant().toEpochMilli(), 3);
    path = replace(path, "ms", dateTime.toInstant().toEpochMilli(), 0);

    return path;//w  w w  .  j  a  va2  s  .c  om
}