Example usage for java.time Year of

List of usage examples for java.time Year of

Introduction

In this page you can find the example usage for java.time Year of.

Prototype

public static Year of(int isoYear) 

Source Link

Document

Obtains an instance of Year .

Usage

From source file:Main.java

public static void main(String[] args) {
    Year y = Year.of(2014);
    LocalDate l = y.atMonthDay(MonthDay.of(Month.JANUARY, 21));
    System.out.println(l);/* ww  w . ja  v a  2  s  . co  m*/

}

From source file:Main.java

public static void main(String[] args) {
    Year currentYear = Year.now();
    Year twoThousand = Year.of(2000);
    boolean isLeap = currentYear.isLeap(); // false
    int length = currentYear.length(); // 365

    // sixtyFourth day of 2014 (2014-03-05)
    LocalDate date = Year.of(2014).atDay(64);

    System.out.println("year: currentYear: " + currentYear);
    System.out.println("year: twoThousand: " + twoThousand);
    System.out.println("year: isLeap: " + isLeap);
    System.out.println("year: length: " + length);
    System.out.println("year: date: " + date);
}

From source file:Main.java

public static void main(String[] args) {
    Year year_2014 = Year.of(2014);
    System.out.println(year_2014);

    LocalDate year_month_day = Year.of(2014).atMonth(3).atDay(23);
    System.out.println(year_month_day);

    LocalDate year_and_day = Year.of(1974).atDay(77); // 1974-03-18
    System.out.println(year_and_day);

    System.out.println(MonthDay.of(Month.FEBRUARY, 29));

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15
    System.out.println(date.getYear()); // 2014
    System.out.println(date.getDayOfYear()); // 46
    System.out.println(date.lengthOfYear()); // 365
    System.out.println(date.isLeapYear()); // false

    Year year_2014 = Year.of(2014);
    System.out.println(year_2014.isLeap()); // false
}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-07-16T10:15:30.00Z");
    LocalDate localDate = LocalDate.parse("2014-07-16", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    LocalDate localDate2 = LocalDate.parse("2014-07-16", DateTimeFormatter.ISO_LOCAL_DATE);

    DateTimeFormatter strangeFormat = new DateTimeFormatterBuilder().appendValue(MONTH_OF_YEAR, 2)
            .appendLiteral("==").appendValue(YEAR, 4).appendLiteral("--").appendValue(DAY_OF_MONTH, 2)
            .toFormatter();/*from  w  w  w.  ja  v a  2 s . c o  m*/

    LocalDate localDate3 = LocalDate.parse("07==2014--16", strangeFormat);

    System.out.println(instant);
    System.out.println(localDate);
    System.out.println(localDate2);
    System.out.println(localDate3);

    LocalDate date = Year.of(2014).atMonth(7).atDay(16);
    String strangeDateFormat = date.format(strangeFormat);

    System.out.println(strangeDateFormat);
}

From source file:MonthsInYear.java

public static void main(String[] args) {
    int year = 0;

    if (args.length <= 0) {
        System.out.printf("Usage: MonthsInYear <year>%n");
        throw new IllegalArgumentException();
    }//  ww  w .  jav a 2 s  .com

    try {
        year = Integer.parseInt(args[0]);
    } catch (NumberFormatException nexc) {
        System.out.printf("%s is not a properly formatted number.%n", args[0]);
        throw nexc; // Rethrow the exception.
    }

    try {
        Year test = Year.of(year);
    } catch (DateTimeException exc) {
        System.out.printf("%d is not a valid year.%n", year);
        throw exc; // Rethrow the exception.
    }

    System.out.printf("For the year %d:%n", year);
    for (Month month : Month.values()) {
        YearMonth ym = YearMonth.of(year, month);
        System.out.printf("%s: %d days%n", month, ym.lengthOfMonth());
    }
}

From source file:Main.java

private static LocalDate thanksgiving(int year) {
    LocalDate thanksGiving = Year.of(year).atMonth(Month.NOVEMBER).atDay(1)
            .with(TemporalAdjusters.lastInMonth(DayOfWeek.WEDNESDAY));
    return thanksGiving;
}

From source file:org.springsource.restbucks.payment.CreditCardRepositoryIntegrationTest.java

public static CreditCard createCreditCard() {

    CreditCardNumber number = new CreditCardNumber("4321432143214321");
    return new CreditCard(number, "Oliver Gierke", Month.DECEMBER, Year.of(2020));
}

From source file:org.springsource.restbucks.payment.PaymentInitializer.java

@Autowired
public PaymentInitializer(CreditCardRepository repository) {

    if (repository.count() > 0) {
        return;/*from  w w w. java2  s  .com*/
    }

    CreditCardNumber number = new CreditCardNumber("1234123412341234");
    CreditCard creditCard = new CreditCard(number, "Oliver Gierke", Month.DECEMBER, Year.of(2099));

    creditCard = repository.save(creditCard);

    LOG.info("Credit card {} created!", creditCard);
}

From source file:org.springsource.restbucks.payment.PaymentServiceImplUnitTest.java

@Test
public void throwsOrderPaidEventOnPayment() {

    CreditCard creditCard = new CreditCard(NUMBER, "Oliver Gierke", Month.JANUARY, Year.of(2020));
    when(creditCardRepository.findByNumber(NUMBER)).thenReturn(Optional.of(creditCard));

    Order order = new Order();
    ReflectionTestUtils.setField(order, "id", 1L);

    paymentService.pay(order, NUMBER);/*from ww  w .  j  a v a2  s  . c  o  m*/

    verify(publisher).publishEvent(Mockito.any((OrderPaidEvent.class)));
}