本文整理汇总了Java中java.time.ZonedDateTime.withZoneSameLocal方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.withZoneSameLocal方法的具体用法?Java ZonedDateTime.withZoneSameLocal怎么用?Java ZonedDateTime.withZoneSameLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.withZoneSameLocal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_withZoneSameLocal
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameLocal() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.withZoneSameLocal(ZONE_0200);
assertEquals(test.toLocalDateTime(), base.toLocalDateTime());
}
示例2: test_withZoneSameLocal_noChange
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameLocal_noChange() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
ZonedDateTime test = base.withZoneSameLocal(ZONE_0100);
assertEquals(test, base);
}
示例3: test_withZoneSameLocal_retainOffset1
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameLocal_retainOffset1() {
LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0); // overlap
ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") );
ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
}
示例4: test_withZoneSameLocal_retainOffset2
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameLocal_retainOffset2() {
LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0); // overlap
ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );
ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
示例5: test_printText
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_printText() {
Random r = RandomFactory.getRandom();
int N = 8;
Locale[] locales = Locale.getAvailableLocales();
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
ZonedDateTime zdt = ZonedDateTime.now();
//System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
while (N-- > 0) {
zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
.with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
for (String zid : zids) {
if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
continue; // TBD: match jdk behavior?
}
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
TimeZone tz = TimeZone.getTimeZone(zid);
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
for (Locale locale : locales) {
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
|| (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
continue;
}
printText(locale, zdt, TextStyle.FULL, tz,
tz.getDisplayName(isDST, TimeZone.LONG, locale));
printText(locale, zdt, TextStyle.SHORT, tz,
tz.getDisplayName(isDST, TimeZone.SHORT, locale));
}
}
}
}
示例6: getTimestamp
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private Timestamp getTimestamp(final String datetimeString) {
final DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
final ZonedDateTime dateTime = ZonedDateTime.parse(datetimeString.replace(" ", "T").replace(".0", "+00:00"), formatter);
final ZonedDateTime zonedDateTime = dateTime.withZoneSameLocal(DatumUtil.NL_ZONE_ID);
return new Timestamp(zonedDateTime.toInstant().toEpochMilli());
}
示例7: test_withZoneSameLocal_null
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_withZoneSameLocal_null() {
LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
base.withZoneSameLocal(null);
}