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 ...
随机推荐
- 微信小程序 - tab+swiper切换(非组件)
无奈slot不支持循环,无法成为组件. 该模板适用于新闻等,点击下载示例:tabswiper
- JAVA动态编译辅助类
一.场景 平时我们学学用到在JVM运行时,动态编译.java的源代码情况,比如作为灵活的配置文件.这时候就要用到动态编译,参考下列. 二.类内容 1.引入依赖: <!-- https://mvn ...
- 算法笔记_203:第四届蓝桥杯软件类决赛真题(C语言B组)
目录 1 猜灯谜 2 连续奇数和 3 空白格式化 4 高僧斗法 5 格子刷油漆 6 农场阳光 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 猜灯谜 标题:猜灯谜 A 村的元宵节灯会上有一迷题: ...
- mysql可视化工具
比较mysql manager lite 和phpmyadmin: 1.phpmyadmin有中文界面, 可以快速入门,但友好性远没有SQL Manager Lite强大 2.SQL Manager ...
- django之创建第7-1个项目-url配置高级
修改urls.PY文件 # -*- coding: UTF-8 -*- from django.conf.urls import patterns, include, url # Uncomment ...
- spark的外排:AppendOnlyMap与ExternalAppendOnlyMap
相信很多人和我一样, 在控制台中总是可以看到会打印出如下的语句: INFO ExternalAppendOnlyMap: Thread 94 spilling in-memory map of 63. ...
- C# 多线程并发锁模式-总结
开篇: 互斥还是lock Monitor Mutex 模式! Muex Monitor lock AutoEventSet ManualEventSet 后续的 ReaderWriterLock ...
- firefox插件卸载
1.根据插件名进行搜索,搜索到相关dll后删除,重启firefox. 2.about:config--plugin.expose_full_path:true,然后about:plugins去查看插件 ...
- oracle安装后tnsnames.ora内容
# tnsnames.ora Network Configuration File: D:\Develop\oracle11g\product\11.2.0\dbhome_1\network\admi ...
- Java成神之路[转]
阿里大牛珍藏架构资料,点击链接免费获取 针对本文,博主最近在写<成神之路系列文章> ,分章分节介绍所有知识点.欢迎关注. 主要版本 更新时间 备注 v1.0 2015-08-01 首次发布 ...