Java 8 – Convert Instant to ZonedDateTime
1. Instant -> ZonedDateTime
Example to convert a Instant UTC+0 to a Japan ZonedDateTime UTC+9
package com.mkyong.date;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class InstantZonedDateTime1 {
public static void main(String[] argv) {
// Z = UTC+0
Instant instant = Instant.now();
System.out.println("Instant : " + instant);
// Japan = UTC+9
ZonedDateTime jpTime = instant.atZone(ZoneId.of("Asia/Tokyo"));
System.out.println("ZonedDateTime : " + jpTime);
System.out.println("OffSet : " + jpTime.getOffset());
}
}
Output
Instant : 2016-08-18T06:17:10.225Z
LocalDateTime : 2016-08-18T06:17:10.225
2. ZonedDateTime -> Instant
Convert the Japan ZonedDateTime UTC+9 back to a Instant UTC+0/Z, review the result, the offset is taken care automatically.
package com.mkyong.date;
import java.time.*;
public class InstantZonedDateTime2 {
public static void main(String[] argv) {
LocalDateTime dateTime = LocalDateTime.of(2016, Month.AUGUST, 18, 6, 57, 38);
// UTC+9
ZonedDateTime jpTime = dateTime.atZone(ZoneId.of("Asia/Tokyo"));
System.out.println("ZonedDateTime : " + jpTime);
// Convert to instant UTC+0/Z , java.time helps to reduce 9 hours
Instant instant = jpTime.toInstant();
System.out.println("Instant : " + instant);
}
}
Output
ZonedDateTime : 2016-08-18T06:57:38+09:00[Asia/Tokyo]
Instant : 2016-08-17T21:57:38Z
http://www.mkyong.com/java8/java-8-convert-instant-to-zoneddatetime/
http://www.mkyong.com/tutorials/java-date-time-tutorials/
Java 8 – Convert Instant to ZonedDateTime的更多相关文章
- Java 8 – Convert Instant to LocalDateTime
Java 8 examples to show you how to convert from Instant to LocalDateTime 1. Instant -> LocalDateT ...
- Java 8 – Convert Map to LIST
Java 8 – Convert Map to LIST Few Java examples to convert a Map to a List Map<String, String> ...
- Java 8 – Convert List to Map
Java 8 – Convert List to Map package com.mkyong.java8 public class Hosting { private int Id; private ...
- Java 8 – Convert a Stream to LIST
Java 8 – Convert a Stream to LIST package com.mkyong.java8; import java.util.List;import java.util.s ...
- java 8时间使用LocalDateTime,ZonedDateTime,LocalDate
前言 java 8的时间已经能够满足日常的使用,也方便理解.joda-time作为一个有优秀的时间组件也不得不告知使用者在java 8以后使用自带的时间 LocalDateTime以及ZonedDat ...
- MyEclipse中将普通Java项目convert(转化)为Maven项目
在MyEclipse10中将Maven项目转成普通Java项目后,想将Java项目转成Maven项目,结果一下子傻眼了.根本就没有攻略中提到的config标签.仔细一看,喵咪的,人家用的是Eclips ...
- Java——Read/convert an InputStream to a String
获取 InputStream 并将其转换为String的简单方法. 添加commons-io-2.4.jar import java.io.IOException; import java.io.In ...
- Java-convert between INT and STRING
int -> String 三种写法 String s = 43 + ""; String s = String.valueOf(43); String s = Intege ...
- Java 8 Date Time API Example Tutorial – LocalDate, Instant, LocalDateTime, Parse and Format
参考 Java 8 Date and Time API is one of the most sought after change for developers. Java has been mis ...
随机推荐
- ubuntu建立快捷方式
拷贝一下文件到新的文件里 [Desktop Entry]Categories=Development;Comment[zh_CN]=Comment=Exec=/usr/local/idea-IU-17 ...
- 一次性解决Intellij IDEA maven 自动跳到1.5的JDK
说明:文章学习自:https://blog.csdn.net/Zereao/article/details/77427989 一.找到Setting.xml文件 打开setting.xml 说明,该文 ...
- h5画图表
折线: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&q ...
- NGUI 降低drawcall
前置说明一: Unity中的drawcall定义: 每次引擎准备数据并通知GPU的过程称为一次Draw Call. Unity(或者说基本全部图形引擎)生成一帧画面的处理过程大致能够这样简化描写叙述: ...
- spring 配置bean的方法及依赖注入发方式
Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & 实例工厂方法).FactoryBean 这里依据全类名配置bean <bean id="helloWo ...
- 【Linux】&、&&、|、||的用法说明
在Linux系统中,&.&&.|.||的用法如下: & 表示任务在后台运行,例如:ping 127.0.0.1>a.txt& && 表 ...
- python之模块pprint之常见用法
# -*- coding: cp936 -*- #python 27 #xiaodeng #python之模块pprint之常见用法 import pprint data = [(1,{'a':'A' ...
- VB按字节截取字符串
内容绝大部分来自互联网,出处请百度. 全角半角皆适用 Public Function bSubstring(ByVal s As String, ByVal length As Integer) As ...
- Condition Variables
Condition Variables Condition variables are synchronization primitives that enable threads to wait u ...
- 解决CSS的position:absolute中left效果
有时候css中设置了position:absolute,left:100px,但是如果我们不想要这个left怎么办呢,当然你直接删除就可以,但是如果是框架的css,你直接删除就有问题了,这时候该怎么办 ...