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 ...
随机推荐
- Windows上Boost的编译步骤
一.FQ下载Boost最新版本 官网:http://www.boost.org/ 假设解压到:D:\Applicaton\DevTools\boost\boost_1_65_1 二.使用VS编译器 c ...
- kafka文档(转)
来自:http://www.inter12.org/archives/842 一 BROKER 的全局配置 最为核心的三个配置 broker.id.log.dir.zookeeper.connect ...
- 自己定义RatingBar,能依据设置改变样式
项目在我的GITHUB上 mirsfang的GitHub 一个简单的自己定义View ,为了一个 比較奇葩的需求而搞出来的.他的功能就是能让你自己设置图片和图片的大小以及星星的数量,是一个组合型的 ...
- TxQueryRunner-JDBC小工具
1.TxQueryRunner的简介(需要相关jar包的请留言) TxQueryRunner类是common-dbutils下QueryRunner的子类,是用来简化JDBC操作的,所以要导入comm ...
- Flink流处理之迭代案例
当前Flink将迭代的重心集中在批处理上,之前我们谈及了批量迭代和增量迭代主要是针对批处理(DataSet)API而言的,而且Flink为批处理中的迭代提供了针对性的优化. 可是对于流处理(DataS ...
- centos7 计划任务 crontab的使用
#vim /etc/crontab #号代表以管理员身份运行. 将你要执行的脚本或者命令加进去,例如我的: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr ...
- 图解Win7如何手动添加受信任证书
点击开始—>运行,如下图所示: 弹出“控制台”窗口如下,如下图所示: 点击“文件—添加/删除管理单元”,如下图所示: 选择“证书”,并点击“添加”,如下图所示: 在弹出的窗口上选 ...
- jenkins+maven+junit构建自动化测试,整合junit xml生成直观的测试报告[留存]
在自动化测试过程中,测试报告最能直观的体现测试的价值,之前一直使用maven+junit来构建我的自动化测试,但这样有几个缺点,一是,不能定时构建自动化任务(也许是我没有找到maven有没有提供这样的 ...
- centos6.5关闭ipv6
万境归空,道法自然 1.在/etc/modprobe.d/目录下增加一个新的配置文件ipv6.conf cat << EOF > /etc/modprobe.d/ipv6.confa ...
- quartz持久化部署实现
http://blog.csdn.net/wxniitxueyuan/article/details/50477712