本文整理汇总了Java中java.time.LocalDateTime.atZone方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.atZone方法的具体用法?Java LocalDateTime.atZone怎么用?Java LocalDateTime.atZone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.atZone方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRecentJoin
import java.time.LocalDateTime; //导入方法依赖的package包/类
private boolean isRecentJoin(UgcPlayer.Membership team) {
if (team.getJoinedTeam() == null || !"true".equals(team.getActive())) {
return false;
}
LocalDateTime date = LocalDateTime.parse(team.getJoinedTeam(), DateTimeFormatter.ofPattern(UGC_NEW_DATE_FORMAT, Locale.ENGLISH));
ZonedDateTime join = date.atZone(UGC_ZONE_ID);
return ZonedDateTime.now().minusHours(18).isBefore(join);
}
示例2: test_print
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
ZonedDateTime zdt = ldt.atZone(zone);
builder.appendOffset(offsetPattern, noOffset);
String output = builder.toFormatter().format(zdt);
assertEquals(output, expected);
}
示例3: test_print_localized
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print_localized")
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
ZonedDateTime zdt = ldt.atZone(offset);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
.toFormatter();
assertEquals(f.format(odt), expected);
assertEquals(f.format(zdt), expected);
assertEquals(f.parse(expected, ZoneOffset::from), offset);
if (style == TextStyle.FULL) {
f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
.toFormatter();
assertEquals(f.format(odt), expected);
assertEquals(f.format(zdt), expected);
assertEquals(f.parse(expected, ZoneOffset::from), offset);
f = new DateTimeFormatterBuilder().appendPattern("OOOO")
.toFormatter();
assertEquals(f.format(odt), expected);
assertEquals(f.format(zdt), expected);
assertEquals(f.parse(expected, ZoneOffset::from), offset);
}
if (style == TextStyle.SHORT) {
f = new DateTimeFormatterBuilder().appendPattern("O")
.toFormatter();
assertEquals(f.format(odt), expected);
assertEquals(f.format(zdt), expected);
assertEquals(f.parse(expected, ZoneOffset::from), offset);
}
}
示例4: test_toInstant_UTC
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec);
assertEquals(test.getNano(), expectedNos);
}
示例5: test_print
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print(LocalDateTime ldt, ZoneId zone, String expected) {
ZonedDateTime zdt = ldt.atZone(zone);
builder.appendZoneId();
String output = builder.toFormatter().format(zdt);
assertEquals(output, expected);
}
示例6: test_print_pattern_VV
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print_pattern_VV(LocalDateTime ldt, ZoneId zone, String expected) {
ZonedDateTime zdt = ldt.atZone(zone);
builder.appendPattern("VV");
String output = builder.toFormatter().format(zdt);
assertEquals(output, expected);
}
示例7: test_print_pattern_x
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
String pattern = null;
String zero = null;
if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
pattern = "x";
zero = "+00";
} else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
pattern = "xx";
zero = "+0000";
} else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) {
pattern = "xxx";
zero = "+00:00";
} else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) {
pattern = "xxxx";
zero = "+0000";
} else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
pattern = "xxxxx";
zero = "+00:00";
}
if (pattern != null) {
ZonedDateTime zdt = ldt.atZone(zone);
builder.appendPattern(pattern);
String output = builder.toFormatter().format(zdt);
assertEquals(output, (expected.equals("Z") ? zero : expected));
}
}
示例8: test_toInstant_P0100
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_0100);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
assertEquals(test.getNano(), expectedNos);
}
示例9: test_toInstant_M0100
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_M0100);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
assertEquals(test.getNano(), expectedNos);
}
示例10: test_toEpochSecond_UTC
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
assertEquals(dt.toEpochSecond(), expectedEpSec);
}
示例11: test_toEpochSecond_P0100
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_0100);
assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
}
示例12: test_atZone_nullTimeZone
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_atZone_nullTimeZone() {
LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
t.atZone((ZoneId) null);
}
示例13: test_toEpochSecond_M0100
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_M0100);
assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
}