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: ...
随机推荐
- JavaScript正则式练习
使用正则式匹配第一个数字和最后一个数字,使用环视 str2 = 09051 : Fast Food Restaurants - Concession Stands/Snack Bars Delicat ...
- 利用 pywin32 操作 excel
from win32com.client import Dispatch import win32com.client import time # 获取excel 对象 excel = win32co ...
- Executor并发框架--线程池,ThreadToolExecutor初步
Executor存在的目的是提供一种将"任务提交"与"任务如何运行"分离开来的机制.虽然只有一个方法,但是却为灵活且强大的异步任务执行框架提供了基础.它提供了一 ...
- springMvc基于注解登录拦截器
1.首先先定义一个拦截器注解 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) p ...
- Win10 PLSQL 登录后,提示数据库字符集(AL32UTF8)和客户端字符集(ZHS16GBK)不一致
plsql 登录后提示: Database character set (AL32UTF8) and Client character set (ZHS16GBK) are different.Cha ...
- Nginx 与Tomcat 实现动静态分离、负载均衡
Nginx 与Tomcat 实现动静态分离.负载均衡 一.Nginx简介: Nginx一个高性能的HTTP和反向代理服务器, 具有很高的稳定性和支持热部署.模块扩展也很容易.当遇到访问的峰值,或者有人 ...
- SpringMVC学习笔记一:基本概念,执行流程与开发步骤
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6831328.html 一:基本概念 DispatcherServlet:前端控制器,负责把请求分发处理. H ...
- android JNI调用(Android Studio 3.0.1)(转)
最近回头复习了一下android 的jni调用,却发现按以前的方法调用失败,一怒之下就重新摸索,碰了几次壁,发现网上好多教程都不能成功调用,于是记录一下现在AS版本成功好用的调用方法. 这里设定你的n ...
- Dubbo源码解读:appendAnnotation [01]
import java.lang.reflect.Method; public class AppendAnnotation { /** * 获取某个Annotation实例的所有方法值(实际是Ann ...
- ROS中发布IMU传感器消息
下面使用SYD Dynamics的9轴AHRS(Attitude and heading reference system),来发布sensor_msgs/Imu类型的消息. 将传感器用USB转串口接 ...