Java 8 – Convert Instant to LocalDateTime
Java 8 examples to show you how to convert from Instant to LocalDateTime
1. Instant -> LocalDateTime
The java.time.LocalDateTime has no concept of time zone, just provide a zero offset UTC+0.
package com.mkyong.date;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
public class InstantExample1 {
public static void main(String[] argv) {
// Parse a ISO 8601 Date directly
//Instant instant = Instant.parse("2016-08-18T06:17:10.225Z");
Instant instant = Instant.now();
System.out.println("Instant : " + instant);
//Convert instant to LocalDateTime, no timezone, add a zero offset / UTC+0
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
System.out.println("LocalDateTime : " + ldt);
}
}
Output
Instant : 2016-08-18T06:17:10.225Z
LocalDateTime : 2016-08-18T06:17:10.225
2. LocalDateTime -> Instant
package com.mkyong.date;
import java.time.*;
public class InstantExample2 {
public static void main(String[] argv) {
// Hard code a date time
LocalDateTime dateTime = LocalDateTime.of(2016, Month.AUGUST, 18, 6, 17, 10);
System.out.println("LocalDateTime : " + dateTime);
// Convert LocalDateTime to Instant, UTC+0
Instant instant = dateTime.toInstant(ZoneOffset.UTC);
System.out.println("Instant : " + instant);
}
}
Instant : 2016-08-18T06:17:10.225Z
LocalDateTime : 2016-08-18T06:17:10.225
http://www.mkyong.com/java8/java-convert-instant-to-localdatetime/
http://www.mkyong.com/tutorials/java-date-time-tutorials/
Java 8 – Convert Instant to LocalDateTime的更多相关文章
- Java 8 – Convert Instant to ZonedDateTime
1. Instant -> ZonedDateTime Example to convert a Instant UTC+0 to a Japan ZonedDateTime UTC+9 Ins ...
- java日期互转:LocalDateTime、String、TimeStamp、Long、Instant、Date
由于java版本的迭代,一个使用java开发的项目中可能出现多种日期对象,例如LocalDateTime.LocalDate.Date,不像C#只有一个DateTime,因此在各种日期格式或者对象之间 ...
- Java 8 中 Date与LocalDateTime、LocalDate、LocalTime互转
Java 8中 java.util.Date 类新增了两个方法,分别是from(Instant instant)和toInstant()方法 // Obtains an instance of Dat ...
- 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 ...
- Convert Date between LocalDateTime
http://blog.progs.be/542/date-to-java-time Java8 has new date and time classes to “replace” the old ...
- Java 8 – How to format LocalDateTime
Few examples to show you how to format java.time.LocalDateTime in Java 8. 1. LocalDateTime + DateTim ...
- JAVA中JDK1.8的LocalDateTime日期类的操作方法
LocalDateTime与Date相互转换参考:https://www.cnblogs.com/pxblog/p/13745972.html 关键类 Instant:瞬时时间. LocalDate: ...
随机推荐
- vCenter 5.1 U1 Installation: Part 9 (vCenter SSO Configuration)
http://www.derekseaman.com/2012/09/vmware-vcenter-51-installation-part-9.html In this installment of ...
- 使用Spring框架入门二:基于注解+XML配置的IOC/DI的使用
一.简述 本文主要讲使用注解+xml配合使用的几种使用方式.基础课程请看前一节. 二.步骤 1.为Pom.xml中引入依赖:本例中使用的是spring-context包,引入此包时系统会自动导入它的依 ...
- HttpLuaModule——翻译(Nginx API for Lua)
现在我已经将翻译的内容放到:http://wiki.nginx.org/HttpLuaModuleZh Nginx API for Lua Introduction 各种各样的*_by_lua和*_b ...
- Spark的运行模式(1)--Local和Standalone
Spark一共有5种运行模式:Local,Standalone,Yarn-Cluster,Yarn-Client和Mesos. 1. Local Local模式即单机模式,如果在命令语句中不加任何配置 ...
- APP注册邀请码
小火箭:MrZOpba685OMLSpanBKFtkxcQf5eGOY 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论
- Java常用的非受检异常
IllegalArgumentException 非 null 的参数值不正确 IllegalStateException 对于方法调用而言,对象状态不合适 NullPointException 参数 ...
- wordpress 开源博客系统部署
1.开发工具 server apache 下载地址:http://www.apache.org http://httpd.apache.org/download.cgi 数据库 mys ...
- notepad++插件实现json、xml格式化
notepad++比较出色的免费的数据编辑.格式化工具... 现在json.xml文件很流行.格式化也是必须的,方便查看关键信息! 01.下载notepad++及相关插件 npp_7.5.5-x86: ...
- Region使用全解
代码地址如下:http://www.demodashi.com/demo/14799.html 前言 Region,即为区域,它表示的是canvas图层上的某一块封闭的区域.很多时候,我们会利用Reg ...
- Effective Tensorflow[转]
Effective TensorFlow Table of Contents TensorFlow Basics Understanding static and dynamic shapes Sco ...