- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.ZonedDateTime.of()
方法的一些代码示例,展示了ZonedDateTime.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.of()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:of
[英]Obtains an instance of ZonedDateTime from a year, month, day, hour, minute, second, nanosecond and time-zone.
This creates a zoned date-time matching the local date-time of the seven specified fields as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may be adjusted.
The local date-time is resolved to a single instant on the time-line. This is achieved by finding a valid offset from UTC/Greenwich for the local date-time as defined by the ZoneRules of the zone ID.
In most cases, there is only one valid offset for a local date-time. In the case of an overlap, when clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer".
In the case of a gap, when clocks jump forward, there is no valid offset. Instead, the local date-time is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the local date-time will be moved one hour later into the offset typically corresponding to "summer".
This method exists primarily for writing test cases. Non test-code will typically use other methods to create an offset time. LocalDateTime has five additional convenience variants of the equivalent factory method taking fewer arguments. They are not provided here to reduce the footprint of the API.
[中]从年、月、日、小时、分钟、秒、纳秒和时区获取ZoneDateTime的实例。
这将创建与七个指定字段的本地日期时间尽可能接近的分区日期时间。时区规则(如夏令时)意味着并非每个本地日期时间都对指定的区域有效,因此可以调整本地日期时间。
本地日期时间解析为时间线上的一个瞬间。这是通过查找由分区ID的分区表定义的本地日期时间与UTC/格林威治的有效偏移量来实现的。
在大多数情况下,本地日期时间只有一个有效偏移量。在重叠的情况下,当时钟被向后设置时,有两个有效偏移。此方法使用通常与“summer”对应的较早偏移量。
在间隙的情况下,当时钟向前跳时,没有有效的偏移。相反,本地日期时间会根据间隔的长度调整为更晚。对于典型的一小时夏令时更改,本地日期时间将在一小时后移动到通常对应于“夏季”的偏移量中。
这种方法主要用于编写测试用例。非测试代码通常会使用其他方法来创建偏移时间。LocalDateTime有五个附加的方便变量,它们是等效工厂方法的变体,使用的参数更少。这里不提供它们是为了减少API的占用空间。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public ZonedDateTime createdAt() {
return ZonedDateTime.of(2016, 12, 16, 12, 35, 0, 0, ZoneOffset.UTC);
}
代码示例来源:origin: neo4j/neo4j
private static ZonedDateTime newZonedDateTime( long epochSecondLocal, long nano, ZoneId zoneId )
{
Instant instant = Instant.ofEpochSecond( epochSecondLocal, nano );
LocalDateTime localDateTime = LocalDateTime.ofInstant( instant, UTC );
return ZonedDateTime.of( localDateTime, zoneId );
}
}
代码示例来源:origin: oblac/jodd
/**
* Converts local date time to Calendar.
*/
public static Calendar toCalendar(final LocalDateTime localDateTime) {
return GregorianCalendar.from(ZonedDateTime.of(localDateTime, ZoneId.systemDefault()));
}
代码示例来源:origin: neo4j/neo4j
public static DateTimeValue datetime(
int year, int month, int day, int hour, int minute, int second, int nanoOfSecond, ZoneId zone )
{
return new DateTimeValue( assertValidArgument(
() -> ZonedDateTime.of( year, month, day, hour, minute, second, nanoOfSecond, zone ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingDateTimeArray() throws Exception
{
Object o0 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 0, ZoneId.of( "UTC" ) )};
Object o1 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 1, ZoneId.of( "UTC" ) )};
Object o2 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 2, ZoneId.of( "UTC" ) )};
Object o3 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 3, ZoneId.of( "UTC" ) )};
Object o4 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 4, ZoneId.of( "UTC" ) )};
Object o5 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 5, ZoneId.of( "UTC" ) )};
shouldRangeSeekInOrder( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingDateTimeArray() throws Exception
{
Object o0 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 0, ZoneId.of( "UTC" ) )};
Object o1 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 1, ZoneId.of( "UTC" ) )};
Object o2 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 2, ZoneId.of( "UTC" ) )};
Object o3 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 3, ZoneId.of( "UTC" ) )};
Object o4 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 4, ZoneId.of( "UTC" ) )};
Object o5 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 5, ZoneId.of( "UTC" ) )};
shouldSeekInOrderExactWithRange( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingDateTimeArray() throws Exception
{
Object o0 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 0, ZoneId.of( "UTC" ) )};
Object o1 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 1, ZoneId.of( "UTC" ) )};
Object o2 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 2, ZoneId.of( "UTC" ) )};
Object o3 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 3, ZoneId.of( "UTC" ) )};
Object o4 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 4, ZoneId.of( "UTC" ) )};
Object o5 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 5, ZoneId.of( "UTC" ) )};
shouldRangeSeekInOrder( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingDateTimeArray() throws Exception
{
Object o0 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 0, ZoneId.of( "UTC" ) )};
Object o1 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 1, ZoneId.of( "UTC" ) )};
Object o2 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 2, ZoneId.of( "UTC" ) )};
Object o3 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 3, ZoneId.of( "UTC" ) )};
Object o4 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 4, ZoneId.of( "UTC" ) )};
Object o5 = new ZonedDateTime[]{ZonedDateTime.of( 10, 10, 10, 10, 10, 10, 5, ZoneId.of( "UTC" ) )};
shouldSeekInOrderExactWithRange( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
public static DateTimeValue datetime( DateValue date, LocalTimeValue time, ZoneId zone )
{
return new DateTimeValue( ZonedDateTime.of( date.temporal(), time.temporal(), zone ) );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void lastModified() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setLastModified(lastModified.toInstant().toEpochMilli());
HeaderAssertions assertions = headerAssertions(headers);
assertions.lastModified(lastModified.toInstant().toEpochMilli());
try {
assertions.lastModified(lastModified.toInstant().toEpochMilli() + 1);
fail("Wrong value expected");
}
catch (AssertionError error) {
// Expected
}
}
代码示例来源:origin: neo4j/neo4j
private TemporalValue attachDate( TemporalValue temporal, LocalDate dateToAttach )
{
LocalTime timePart = temporal.getLocalTimePart();
if ( temporal.supportsTimeZone() )
{
// turn time into date time
return datetime( ZonedDateTime.of( dateToAttach, timePart, temporal.getZoneOffset() ) );
}
else
{
// turn local time into local date time
return localDateTime( LocalDateTime.of( dateToAttach, timePart ) );
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void expires() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setExpires(expires);
HeaderAssertions assertions = headerAssertions(headers);
assertions.expires(expires.toInstant().toEpochMilli());
try {
assertions.expires(expires.toInstant().toEpochMilli() + 1);
fail("Wrong value expected");
}
catch (AssertionError error) {
// Expected
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-17330
public void matchDateFormattedWithHttpHeaders() throws Exception {
long epochMilli = ZonedDateTime.of(2018, 10, 5, 0, 0, 0, 0, ZoneId.of("GMT")).toInstant().toEpochMilli();
HttpHeaders headers = new HttpHeaders();
headers.setDate("myDate", epochMilli);
this.response.setHeader("d", headers.getFirst("myDate"));
this.matchers.dateValue("d", epochMilli).match(this.mvcResult);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void createDateTimeFormatterWithTimeZone() {
factory.setPattern("yyyyMMddHHmmss Z");
factory.setTimeZone(TEST_TIMEZONE);
ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
ZonedDateTime dateTime = ZonedDateTime.of(2009, 10, 21, 12, 10, 00, 00, dateTimeZone);
String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200");
assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000 " + offset));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void expiresZonedDateTime() {
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT"));
headers.setExpires(zonedDateTime);
assertEquals("Invalid Expires header", zonedDateTime.toInstant().toEpochMilli(), headers.getExpires());
assertEquals("Invalid Expires header", "Thu, 18 Dec 2008 10:20:00 GMT", headers.getFirst("expires"));
}
代码示例来源:origin: neo4j/neo4j
public static DateTimeValue datetime( DateValue date, TimeValue time )
{
OffsetTime t = time.temporal();
return new DateTimeValue( ZonedDateTime.of( date.temporal(), t.toLocalTime(), t.getOffset() ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
protected DateTimeValue selectDateTime( AnyValue datetime )
{
if ( datetime instanceof DateTimeValue )
{
DateTimeValue value = (DateTimeValue) datetime;
ZoneId zone = optionalTimezone();
return zone == null ? value : new DateTimeValue(
ZonedDateTime.of( value.temporal().toLocalDateTime(), zone ) );
}
if ( datetime instanceof LocalDateTimeValue )
{
return new DateTimeValue( ZonedDateTime.of(
((LocalDateTimeValue) datetime).temporal(), timezone() ) );
}
throw new UnsupportedTemporalUnitException( "Cannot select datetime from: " + datetime );
}
};
代码示例来源:origin: spring-projects/spring-framework
@Test
public void firstZonedDateTime() {
ZonedDateTime date = ZonedDateTime.of(2017, 6, 22, 22, 22, 0, 0, ZoneId.of("GMT"));
headers.setZonedDateTime(HttpHeaders.DATE, date);
assertThat(headers.getFirst(HttpHeaders.DATE), is("Thu, 22 Jun 2017 22:22:00 GMT"));
assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date));
headers.clear();
ZonedDateTime otherDate = ZonedDateTime.of(2010, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT"));
headers.add(HttpHeaders.DATE, RFC_1123_DATE_TIME.format(date));
headers.add(HttpHeaders.DATE, RFC_1123_DATE_TIME.format(otherDate));
assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date));
// obsolete RFC 850 format
headers.clear();
headers.set(HttpHeaders.DATE, "Thursday, 22-Jun-17 22:22:00 GMT");
assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date));
// ANSI C's asctime() format
headers.clear();
headers.set(HttpHeaders.DATE, "Thu Jun 22 22:22:00 2017");
assertTrue(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date));
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldPackLocalDateTimeWithTimeZoneId()
{
LocalDateTime localDateTime = LocalDateTime.of( 1999, 12, 30, 9, 49, 20, 999999999 );
ZoneId zoneId = ZoneId.of( "Europe/Stockholm" );
ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, zoneId );
PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
buffer.getShort(); // skip struct header
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.getNano(), buffer.getInt() );
buffer.getShort(); // skip zoneId string header
byte[] zoneIdBytes = new byte[zoneId.getId().getBytes( UTF_8 ).length];
buffer.get( zoneIdBytes );
assertEquals( zoneId.getId(), new String( zoneIdBytes, UTF_8 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldPackLocalDateTimeWithTimeZoneOffset()
{
LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 );
ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 );
ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset );
PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
buffer.getShort(); // skip struct header
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
assertEquals( localDateTime.getNano(), buffer.get() );
assertEquals( INT_16, buffer.get() );
assertEquals( offset.getTotalSeconds(), buffer.getShort() );
}
我尝试理解[c代码 -> 汇编]代码 void node::Check( data & _data1, vector& _data2) { -> push ebp -> mov ebp,esp ->
我需要在当前表单(代码)的上下文中运行文本文件中的代码。其中一项要求是让代码创建新控件并将其添加到当前窗体。 例如,在Form1.cs中: using System.Windows.Forms; ..
我有此 C++ 代码并将其转换为 C# (.net Framework 4) 代码。有没有人给我一些关于 malloc、free 和 sprintf 方法的提示? int monate = ee; d
我的网络服务器代码有问题 #include #include #include #include #include #include #include int
给定以下 html 代码,将列表中的第三个元素(即“美丽”一词)以斜体显示的 CSS 代码是什么?当然,我可以给这个元素一个 id 或一个 class,但 html 代码必须保持不变。谢谢
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我试图制作一个宏来避免重复代码和注释。 我试过这个: #define GrowOnPage(any Page, any Component) Component.Width := Page.Surfa
我正在尝试将我的旧 C++ 代码“翻译”成头条新闻所暗示的 C# 代码。问题是我是 C# 中的新手,并不是所有的东西都像 C++ 中那样。在 C++ 中这些解决方案运行良好,但在 C# 中只是不能。我
在 Windows 10 上工作,R 语言的格式化程序似乎没有在 Visual Studio Code 中完成它的工作。我试过R support for Visual Studio Code和 R-T
我正在处理一些报告(计数),我必须获取不同参数的计数。非常简单但乏味。 一个参数的示例查询: qCountsEmployee = ( "select count(*) from %s wher
最近几天我尝试从 d00m 调试网络错误。我开始用尽想法/线索,我希望其他 SO 用户拥有可能有用的宝贵经验。我希望能够提供所有相关信息,但我个人无法控制服务器环境。 整个事情始于用户注意到我们应用程
我有一个 app.js 文件,其中包含如下 dojo amd 模式代码: require(["dojo/dom", ..], function(dom){ dom.byId('someId').i
我对“-gencode”语句中的“code=sm_X”选项有点困惑。 一个例子:NVCC 编译器选项有什么作用 -gencode arch=compute_13,code=sm_13 嵌入库中? 只有
我为我的表格使用 X-editable 框架。 但是我有一些问题。 $(document).ready(function() { $('.access').editable({
我一直在通过本教程学习 flask/python http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-wo
我想将 Vim 和 EMACS 用于 CNC、G 代码和 M 代码。 Vim 或 EMACS 是否有任何语法或模式来处理这种类型的代码? 最佳答案 一些快速搜索使我找到了 this vim 和 thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve this
这个问题在这里已经有了答案: Enabling markdown highlighting in Vim (5 个回答) 6年前关闭。 当我在 Vim 中编辑包含 Markdown 代码的 READM
我正在 Swift3 iOS 中开发视频应用程序。基本上我必须将视频 Assets 和音频与淡入淡出效果合并为一个并将其保存到 iPhone 画廊。为此,我使用以下方法: private func d
pipeline { agent any stages { stage('Build') { steps { e
我是一名优秀的程序员,十分优秀!