Example usage for java.time ZonedDateTime of

List of usage examples for java.time ZonedDateTime of

Introduction

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

Prototype

public static ZonedDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second,
        int nanoOfSecond, ZoneId zone) 

Source Link

Document

Obtains an instance of ZonedDateTime from a year, month, day, hour, minute, second, nanosecond and time-zone.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.of(2014, 9, 3, 12, 12, 123, 1234, ZoneId.systemDefault());

    System.out.println(z);//  ww  w. ja  v a  2 s.c  o  m

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime myZonedDateTime = ZonedDateTime.of(2014, 1, 31, 11, 20, 30, 93020122, ZoneId.systemDefault());
    System.out.println(myZonedDateTime);
}

From source file:Main.java

public static void main(String[] args) {

    ZonedDateTime _130AMChicagoTime = ZonedDateTime.of(2014, 3, 9, 1, 30, 0, 0, ZoneId.of("America/Chicago"));

    System.out.println(_130AMChicagoTime.plusHours(3));
    System.out.println(_130AMChicagoTime.plus(Duration.ofHours(3)));

    System.out.println(_130AMChicagoTime.plus(Duration.ofDays(2)));
    System.out.println(_130AMChicagoTime.plus(Period.ofDays(2)));
}

From source file:Main.java

public static void main(String[] argv) {
    ZonedDateTime here = ZonedDateTime.now(ZoneId.of("America/Los_Angeles"));
    ZonedDateTime gmtNewYear = ZonedDateTime.of(2014, 12, 31, 23, 59, 59, 0, ZoneId.of("Europe/London"));

    Duration d = Duration.between(here, gmtNewYear);
    System.out.println(d);//from  w w  w  .  j  av a  2  s  . com
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime zonedDateTime = ZonedDateTime.of(2013, 1, 19, 0, 0, 0, 0, ZoneId.of("Europe/Paris"));

    DateTimeFormatter longDateTimeFormatter = DateTimeFormatter
            .ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL).withLocale(Locale.FRENCH);
    System.out.println(longDateTimeFormatter.getLocale()); // fr
    System.out.println(longDateTimeFormatter.format(zonedDateTime));

}

From source file:Main.java

public static void main(String[] args) {
    TemporalQuery<Integer> daysBeforeChristmas = new TemporalQuery<Integer>() {

        public int daysTilChristmas(int acc, Temporal temporal) {
            int month = temporal.get(ChronoField.MONTH_OF_YEAR);
            int day = temporal.get(ChronoField.DAY_OF_MONTH);
            int max = temporal.with(TemporalAdjusters.lastDayOfMonth()).get(ChronoField.DAY_OF_MONTH);
            if (month == 12 && day <= 25)
                return acc + (25 - day);
            return daysTilChristmas(acc + (max - day + 1),
                    temporal.with(TemporalAdjusters.firstDayOfNextMonth()));
        }//from ww  w . ja  v a 2s. c  o  m

        @Override
        public Integer queryFrom(TemporalAccessor temporal) {
            if (!(temporal instanceof Temporal))
                throw new RuntimeException("Temporal accessor must be of type Temporal");
            return daysTilChristmas(0, (Temporal) temporal);
        }
    };

    System.out.println(LocalDate.of(2013, 12, 26).query(daysBeforeChristmas)); // 364
    System.out.println(LocalDate.of(2013, 12, 23).query(daysBeforeChristmas)); // 2
    System.out.println(LocalDate.of(2013, 12, 25).query(daysBeforeChristmas)); // 0
    System.out.println(ZonedDateTime.of(2013, 12, 1, 11, 0, 13, 938282, ZoneId.of("America/Los_Angeles"))
            .query(daysBeforeChristmas)); // 24
}

From source file:org.nodatime.tzvalidate.Java8Dump.java

@Override
public ZoneTransitions getTransitions(String id, int fromYear, int toYear) {
    ZoneId zone = ZoneId.of(id);
    ZoneRules rules = zone.getRules();
    DateTimeFormatter nameFormat = DateTimeFormatter.ofPattern("zzz", Locale.US);
    ZoneTransitions transitions = new ZoneTransitions(id);

    Instant start = ZonedDateTime.of(fromYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
    transitions.addTransition(null, rules.getOffset(start).getTotalSeconds() * 1000,
            rules.isDaylightSavings(start), nameFormat.format(start.atZone(zone)));
    Instant end = ZonedDateTime.of(toYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();

    ZoneOffsetTransition transition = rules.nextTransition(start.minusNanos(1));
    while (transition != null && transition.getInstant().isBefore(end)) {
        Instant instant = transition.getInstant();
        transitions.addTransition(new Date(instant.toEpochMilli()),
                rules.getOffset(instant).getTotalSeconds() * 1000, rules.isDaylightSavings(instant),
                nameFormat.format(instant.atZone(zone)));
        transition = rules.nextTransition(instant);
    }/*from   w  w  w.  ja va  2 s  .  c  o  m*/
    return transitions;
}

From source file:com.sumzerotrading.intraday.trading.strategy.ReportGeneratorTest.java

@Before
public void setUp() throws Exception {
    orderFilledTime = ZonedDateTime.of(2015, 3, 15, 12, 30, 33, 0, ZoneId.systemDefault());
    reportGenerator = spy(ReportGenerator.class);
    order = new TradeOrder("123", new StockTicker("QQQ"), 100, TradeDirection.BUY);
    order.setOrderFilledTime(orderFilledTime);
    String systemTmpDir = System.getProperty("java.io.tmpdir");
    if (!systemTmpDir.endsWith("/")) {
        systemTmpDir += "/";
    }//from  w  ww  .  j av  a 2 s  .c o m

    System.out.println("System tmp dir is: " + systemTmpDir);
    tmpDir = systemTmpDir + "rg-test/";
    partialDir = tmpDir + "partial/";
    FileUtils.deleteDirectory(new File(tmpDir));
}

From source file:nl.xs4all.home.freekdb.b52reader.general.Utilities.java

/**
 * Create a zoned date(/time). The time part is empty.
 *
 * @param year       year./* w w w  .  ja v a2s . co  m*/
 * @param month      month.
 * @param dayOfMonth day of the month.
 * @return <code>ZonedDateTime</code> object.
 */
public static ZonedDateTime createDate(final int year, final Month month, final int dayOfMonth) {
    return ZonedDateTime.of(year, month.getValue(), dayOfMonth, 0, 0, 0, 0, ZoneOffset.UTC);
}

From source file:alfio.repository.EventRepositoryTest.java

@Test
public void testJavaInsertedDatesRespectTheirTimeZone() throws Exception {
    //these are the values of what we have inserted in the SQL insert script
    ZonedDateTime beginEventDate = ZonedDateTime.of(2015, 4, 18, 0, 0, 0, 0, ZoneId.of("America/New_York"));
    ZonedDateTime endEventDate = ZonedDateTime.of(2015, 4, 19, 23, 59, 59, 0, ZoneId.of("America/New_York"));

    Pair<Integer, Integer> pair = eventRepository.insert("test from unit test", "unittest",
            "http://localhost:8080/", "http://localhost:8080", "http://localhost:8080", "Lugano", "9", "8",
            beginEventDate, endEventDate, NEW_YORK_TZ, 0, "CHF", 4, true, new BigDecimal(1), "", "", 0);
    Event e = eventRepository.findById(pair.getValue());
    assertNotNull("Event not found in DB", e);

    assertEquals("Begin date is not correct", beginEventDate, e.getBegin());
    assertEquals("End date is not correct", endEventDate, e.getEnd());

    //since when debugging the toString method is used .... and it rely on the system TimeZone, we test it too
    System.out.println(e.getBegin().toString());
    System.out.println(e.getEnd().toString());
}