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 ...
随机推荐
- 微软BI 之SSAS 系列 - 基于雪花模型的维度设计
基于雪花模型的维度以下面的 Product 产品与产品子类别,产品类别为例. DimProduct 表和 DimProductSubcategory 表有外键关系,而 DimProductSubcat ...
- NUMA总结。
vsphere 5.1性能最佳实践http://www.vmware.com/pdf/Perf_Best_Practices_vSphere5.1.pdf vNUMA 要求:硬件版本8以上. 1.整个 ...
- HttpLuaModule——翻译(一)
最近经常使用春哥和小哲老师写的NGINX-LUA,非常苦于没有中文文档,特别是向我这种英文水平实在有限的同学,所以将遇到的模块记录下来,供以后参考!原文:http://wiki.nginx.org/H ...
- JSP入门实战下
第一部分简单解说:jsp语法的规范,以及三大编译指令,七个动作指令和九大内置对象,生命周期解说等. 这章主要解说el表达式,核心标签库. 所有代码下载:链接 1.核心标签库(JSTL:c)解说: 1. ...
- SDUT 1269-走迷宫(DFS打印路径)
走迷宫 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 有一个m*n格的迷宫(表示有m行.n列),当中有可走的也有不可走的,假 ...
- 微信小程序字符串如何转数字?
[微信小程序]字符串如何转数字 字符串可以采用 parseInt()方法来转换为数字. input_number_sim = parseInt(input_number_sim) 也可采用的用 ...
- sell 项目 商品表 设计 及 创建
1.数据库表之间的关系说明 2.数据库设计 3.创建 商品表 /** * 商品表 */ create table `product_info` ( `product_id` varchar(32) n ...
- SpringMVC学习笔记五:使用converter进行参数数据转换
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6832898.html 一:SpringMVC数据绑定机制 1:request到达SpringMVC框架时,框 ...
- ssh出错 sign_and_send_pubkey: signing failed: agent refused operation
在服务器添加完公钥之后,ssh服务器然后报了这个错误 sign_and_send_pubkey: signing failed: agent refused operation 然后执行了以下命令才好 ...
- cocos2d-js 免安装在线版 粒子编辑器 particle editor particle builder 兼容pex和plist
http://onebyonedesign.com/flash/particleeditor/ 这个原来是为flash starling设计的粒子系统编辑器,但实际上,还是能兼容cocos2d的. 只 ...