本文整理汇总了Java中java.time.ZonedDateTime.of方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.of方法的具体用法?Java ZonedDateTime.of怎么用?Java ZonedDateTime.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSplitZonedDateTimes
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "directions")
public void testSplitZonedDateTimes(boolean ascending) {
final Duration step = Duration.ofSeconds(1);
final ZonedDateTime start = ZonedDateTime.of(2014, 1, 1, 14, 15, 20, 0, ZoneId.systemDefault());
final ZonedDateTime end = start.plusSeconds(10000000 * (ascending ? 1 : -1));
final Range<ZonedDateTime> range = Range.of(start, end, step);
final List<Range<ZonedDateTime>> segments = range.split();
Assert.assertTrue(segments.size() > 1, "There are multiple segments");
for (int i=1; i<segments.size(); ++i) {
final Range<ZonedDateTime> prior = segments.get(i-1);
final Range<ZonedDateTime> next = segments.get(i);
Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
if (i == segments.size()-1) {
Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
}
}
}
示例2: testSelectWithParallelProcessing
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test()
public void testSelectWithParallelProcessing() {
final ZonedDateTime start = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT"));
final Index<ZonedDateTime> timestamps = Range.of(0, 5000000).map(start::plusMinutes).toIndex(ZonedDateTime.class);
final DataFrame<ZonedDateTime,String> frame = DataFrame.of(timestamps, "C", Double.class);
frame.applyDoubles(v -> Math.random() * 100);
final long expectedRowCount = timestamps.keys().filter(t -> t.getDayOfWeek() == DayOfWeek.MONDAY).count();
final long t1 = System.nanoTime();
final DataFrame<ZonedDateTime,String> select1 = frame.rows().parallel().select(row -> row.key().getDayOfWeek() == DayOfWeek.MONDAY);
final long t2 = System.nanoTime();
final DataFrame<ZonedDateTime,String> select2 = frame.rows().sequential().select(row -> row.key().getDayOfWeek() == DayOfWeek.MONDAY);
final long t3 = System.nanoTime();
System.out.println("Sequential select in " + ((t3-t2)/1000000) + " millis, parallel select in " + ((t2-t1)/1000000) + " millis");
Assert.assertEquals(select1.rowCount(), expectedRowCount, "Selection 1 has expected row count");
Assert.assertEquals(select2.rowCount(), expectedRowCount, "Selection 1 has expected row count");
Assert.assertEquals(select1.colCount(), 1, "Selection 1 has expected column count");
Assert.assertEquals(select2.colCount(), 1, "Selection 1 has expected column count");
DataFrameAsserts.assertEqualsByIndex(select1, select2);
}
示例3: data_adjustInto
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
return new Object[][]{
{LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null},
{LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null},
{LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null},
{LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null},
{LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null},
{LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null},
{LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null},
{LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null},
{LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},
{LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null},
{LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},
{LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null},
{LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null},
{LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null},
{LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null},
{LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
{LocalTime.of(23, 5), null, null, NullPointerException.class},
};
}
示例4: data_instantZones
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@DataProvider(name = "instantZones")
Object[][] data_instantZones() {
return new Object[][] {
{LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 Europe/Paris", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
{LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{LOCALFIELDS_OFFSETID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{LOCALFIELDS_WITH_PARIS, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
{LOCALFIELDS_WITH_0230, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{INSTANT_WITH_PARIS, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(PARIS)},
{INSTANT_WITH_0230, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANT_OFFSETID, "2014-06-30T01:02:03Z +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANT_OFFSETSECONDS, "2014-06-30T01:02:03Z 9000", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANTSECONDS_WITH_PARIS, "86402", Instant.ofEpochSecond(86402).atZone(PARIS)},
{INSTANTSECONDS_NOS_WITH_PARIS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789).atZone(PARIS)},
{INSTANTSECONDS_OFFSETSECONDS, "86402 9000", Instant.ofEpochSecond(86402).atZone(OFFSET_0230)},
};
}
示例5: test_minus_TemporalAmount_Duration
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_minus_TemporalAmount_Duration() {
Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 8, 25, 53, 500), ZONE_0100);
assertEquals(t.minus(duration), expected);
}
示例6: data_formatStyle
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@DataProvider(name="formatStyle")
Object[][] data_formatStyle() {
return new Object[][] {
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM CEST Europe/Paris"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.LONG, "October 2, 2001 1:02:03 AM CEST Europe/Paris"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM Europe/Paris"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.SHORT, "10/2/01 1:02 AM Europe/Paris"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM +02:00 +02:00"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.LONG, "October 2, 2001 1:02:03 AM +02:00 +02:00"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM +02:00"},
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.SHORT, "10/2/01 1:02 AM +02:00"},
};
}
示例7: test_minusYears_zero
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_minusYears_zero() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.minusYears(0);
assertEquals(test, base);
}
示例8: test_withZoneSameInstant
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameInstant() {
ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
ZonedDateTime test = base.withZoneSameInstant(ZONE_0200);
ZonedDateTime expected = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.plusHours(1), ZONE_0200);
assertEquals(test, expected);
}
示例9: testDateJava8
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testDateJava8() throws ParseException, PebbleException, IOException
{
PebbleEngine pebble = new PebbleEngine
.Builder()
.loader(new StringLoader())
.strictVariables(false)
.defaultLocale(Locale.ENGLISH)
.build();
final LocalDateTime localDateTime = LocalDateTime.of(2017, 6, 30, 13, 30, 35, 0);
final ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("GMT+0100"));
final LocalDate localDate = localDateTime.toLocalDate();
final LocalTime localTime = localDateTime.toLocalTime();
StringBuilder source = new StringBuilder();
source
.append("{{ localDateTime | date }}")
.append("{{ localDateTime | date('yyyy-MM-dd HH:mm:ss') }}")
.append("{{ zonedDateTime | date('yyyy-MM-dd HH:mm:ssXXX') }}")
.append("{{ localDate | date('yyyy-MM-dd') }}")
.append("{{ localTime | date('HH:mm:ss') }}");
PebbleTemplate template = pebble.getTemplate(source.toString());
Map<String, Object> context = new HashMap<>();
context.put("localDateTime", localDateTime);
context.put("zonedDateTime", zonedDateTime);
context.put("localDate", localDate);
context.put("localTime", localTime);
Writer writer = new StringWriter();
template.evaluate(writer, context);
assertEquals("2017-06-30T13:30:352017-06-30 13:30:352017-06-30 13:30:35+01:002017-06-3013:30:35", writer.toString());
}
示例10: test_with_adjuster_LocalDate_retainOffset1
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_LocalDate_retainOffset1() {
ZoneId newYork = ZoneId.of("America/New_York");
LocalDateTime ldt = LocalDateTime.of(2008, 11, 1, 1, 30);
ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
}
示例11: test_equals_false_second_differs
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider="sampleTimes")
public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
s = (s == 59 ? 58 : s);
ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s + 1, n), ZONE_0100);
assertEquals(a.equals(b), false);
}
示例12: test_minusWeeks
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_minusWeeks() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.minusWeeks(1);
assertEquals(test, ZonedDateTime.of(ldt.minusWeeks(1), ZONE_0100));
}
示例13: test_plusYears_zero
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_plusYears_zero() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.plusYears(0);
assertEquals(test, base);
}
示例14: testTransactionCollections
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testTransactionCollections() {
WebTarget target = ClientBuilder.newClient().register(JacksonJaxbJsonProvider.class).target("http://localhost:7001/sample");
Map<String, Object> response = target.path("accounts").path("5479-1234567").path("transactions")
.queryParam("sort", "amount::+")
.queryParam("interval", "from::-14d|to::now")
.request()
.accept("application/hal+json")
.header("X-Client-Version", "1.0.0")
.header("X-Service-Generation", "1")
.header("X-Log-Token", DiagnosticContext.getLogToken())
.get(Map.class);
assertNotNull(response.get("_links"));
assertNotNull(response.get("_embedded"));
Map<String, Object> embedded = (Map<String, Object>) response.get("_embedded");
assertEquals(0, ((List) embedded.get("transactions")).size());
ZonedDateTime zd = ZonedDateTime.of(2016, 1, 4, 8, 5, 10, 0, ZoneId.of("UTC"));
response = target.path("accounts").path("5479-1234567").path("transactions")
.queryParam("sort", "amount::+")
.queryParam("interval", "from::" + zd.toInstant().toEpochMilli() + "|to::now")
.request()
.accept("application/hal+json")
.header("X-Client-Version", "1.0.0")
.header("X-Service-Generation", "1")
.header("X-Log-Token", DiagnosticContext.getLogToken())
.get(Map.class);
assertNotNull(response.get("_links"));
assertNotNull(response.get("_embedded"));
embedded = (Map<String, Object>) response.get("_embedded");
assertEquals(6, ((List) embedded.get("transactions")).size());
zd = ZonedDateTime.of(2016, 1, 6, 8, 5, 10, 0, ZoneId.of("UTC"));
response = target.path("accounts").path("5479-1234567").path("transactions")
.queryParam("sort", "amount::+")
.queryParam("interval", "from::" + zd.toInstant().toEpochMilli() + "|to::now")
.request()
.accept("application/hal+json")
.header("X-Client-Version", "1.0.0")
.header("X-Service-Generation", "1")
.header("X-Log-Token", DiagnosticContext.getLogToken())
.get(Map.class);
assertNotNull(response.get("_links"));
assertNotNull(response.get("_embedded"));
embedded = (Map<String, Object>) response.get("_embedded");
assertEquals(0, ((List) embedded.get("transactions")).size());
zd = ZonedDateTime.of(2016, 1, 5, 8, 5, 10, 0, ZoneId.of("UTC"));
response = target.path("accounts").path("5479-1234567").path("transactions")
.queryParam("sort", "amount::+")
.queryParam("interval", "from::" + zd.toInstant().toEpochMilli() + "|to::now")
.request()
.accept("application/hal+json")
.header("X-Client-Version", "1.0.0")
.header("X-Service-Generation", "1")
.header("X-Log-Token", DiagnosticContext.getLogToken())
.get(Map.class);
assertNotNull(response.get("_links"));
assertNotNull(response.get("_embedded"));
embedded = (Map<String, Object>) response.get("_embedded");
assertEquals(4, ((List) embedded.get("transactions")).size());
}
示例15: ofSeconds
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private ZonedDateTime ofSeconds(int seconds) {
return ZonedDateTime.of(0, 1, 1, 0, 0, seconds, 0, ZoneId.systemDefault());
}