ConvertLongToInstantUtil
Posted tonggc1668
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ConvertLongToInstantUtil相关的知识,希望对你有一定的参考价值。
package com.test; import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; public class ConvertLongToInstantUtil { public static void main(String[] args) { System.out.println(parse("2018-09-18T19:01:51.821-04:00")); System.out.println(parseToInstant(1545955200000L)); System.out.println(parseInstantToDefaltDateTime(Instant.now())); } private static String parseInstantToDefaltDateTime(Instant instance) { DateTimeFormatter target = DateTimeFormatter.ofPattern("yyyy-MM-dd‘T‘HH:mm:ss.SSSZ").withZone(ZoneId.systemDefault()); return target.format(instance); } private static OffsetDateTime parseToOffsetDateTime(long instance) { return Instant.ofEpochMilli(instance).atOffset(ZoneOffset.ofHours(-4)); } private static Instant parseToInstant(long instance) { return Instant.ofEpochMilli(instance); } private static long parse(String instance) { OffsetDateTime time = OffsetDateTime.parse(instance); return time.toInstant().toEpochMilli(); } }
以上是关于ConvertLongToInstantUtil的主要内容,如果未能解决你的问题,请参考以下文章