转载自:LocalDateTime To Timestamp Epoch Seconds And Milliseconds

Convert LocalDateTime to seconds since January 1, 1970, 00:00:00 GMT

val now = LocalDateTime.now(ZoneOffset.UTC)

// LocalDateTime to epoch seconds
val seconds = now.atZone(ZoneOffset.UTC).toEpochSecond()) // Epoch seconds to LocalDateTime
val newNow = LocalDateTime.ofInstant(Instant.ofEpochSecond(seconds), ZoneOffset.UTC)

Convert LocalDateTime to milliseconds since January 1, 1970, 00:00:00 GMT

// LocalDateTime to epoch milliseconds
val milliseconds = now.atZone(ZoneOffset.UTC)?.toInstant()?.toEpochMilli() // epoch milliseconds to LocalDateTime
val newNow = LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), ZoneOffset.UTC)

java8 LocalDateTime转unix时间戳(带毫秒,不带毫秒)的更多相关文章

  1. android: 日期转Unix时间戳,Unix时间戳转日期,带时区

    1.UTC时间&GMT时间 UTC时间是时间标准时间(Universal Time Coordinated),UTC是根据原子钟来计算时间,误差非常小. UTC也是指零时区的时间,如果要表示其 ...

  2. 坐上JDK8时间SDK的小船,带你遨游UNIX时间戳与时区的小太空~

    原文链接:坐上JDK8时间SDK的小船,带你遨游UNIX时间戳与时区的小太空- 一.背景: 最近有一个关于店铺数据实时分析的需求,需要实时统计店铺当天的数据:例如访客数,浏览量.商品排行榜等.由于店铺 ...

  3. JavaScript转unix时间戳

    由于 unix 的时间戳是10位不带毫秒的,所以前端获取到时间戳之后需要做一下处理,才能获取正确的时间. // 假设这里是从服务端获取到的时间戳 var unixTime = data.time; / ...

  4. C#中DateTime.Ticks属性及Unix时间戳转换

    1.相关概念 DateTime.Ticks:表示0001 年 1 月 1 日午夜 12:00:00 以来所经历的 100 纳秒数,即Ticks的属性为100纳秒(1Ticks = 0.0001毫秒). ...

  5. js 取得 Unix时间戳(Unix timestamp)

    js 取得 Unix时间戳 Unix时间戳(Unix timestamp),或称Unix时间(Unix time).POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间19 ...

  6. 时间:UTC时间、GMT时间、本地时间、Unix时间戳

    转自:http://blog.csdn.net/u012102306/article/details/51538574 1.UTC时间 与 GMT时间 我们可以认为格林威治时间就是时间协调时间(GMT ...

  7. 简述unix时间戳

    unix时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒. Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix ti ...

  8. 如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)

    Java time JavaScript Math.round(new Date().getTime()/1000)getTime()返回数值的单位是毫秒 Microsoft .NET / C# ep ...

  9. Unix时间戳(Unix timestamp)转换工具

    http://tool.chinaz.com/Tools/unixtime.aspx 现在的Unix时间戳(Unix timestamp)是   1440732364         Unix时间戳( ...

随机推荐

  1. JSP的三个脚本元素

    JSP的脚本:JSP定义Java代码的方式 1. <% 代码 %>:[脚本段:java程序段]定义的java代码,在service方法中.service方法中可以定义什么,该脚本中就可以定 ...

  2. ngnix和负载均衡

    1 准备环境 =====>part1: iptables -F #systemctl disable firewalld #开机默认关闭 #systemctl stop firewalld #立 ...

  3. JS面试Q&A(续2): Rest parameter,Arrow function 等

    rest parameter 和 Destructuring assignment. function fun1(...theArgs) { console.log(theArgs.length);} ...

  4. 用SVG做background image

    1 用utf8格式, 需要 双引号“”替换为单引号,而且采用url encode编码,例如# 替换为 %23, body { background-image: url("data:imag ...

  5. java中二维数组的排序

    首先定义一个5X8的二维数组,然后使用随机数填充满.借助Arrays的方法对二维数组进行排序.参考思路:先把二维数组使用System.arraycopy进行数组复制到一个一维数组然后使用sort进行排 ...

  6. Python全栈开发记录_第六篇(生成器和迭代器)

    说生成器之前先说一个列表生成式:[x for x in range(10)]   ->[0,1,2....,9]这里x可以为函数(因为对python而言就是一个对象而已),range(10)也可 ...

  7. 【Python3学习】Python环境搭建

    以前电脑上安装过一个python2的环境,这次由于项目跟其他团队人员对的时候,人家的是python3,因为python2也没怎么学,所以对里面还是很不了解的. 所以今天就重新开始python3的学习, ...

  8. swagger支持中英文

    内存中使用一种数据结构存储着大量的信息,其中原始的描述信息(各种属性的描述,种类很多),中英文都包含,格式为:"english//中文".需求:描述description需要动态变 ...

  9. LeetCode 100. Same Tree 判断两棵二叉树是否相等 C++

    Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...

  10. 注意source folder与folder是不同的,避免404错误

    在整合ssm框架的时候,程序和配置文件都没写错,tomcat也部署成功了,但在访问的时候一直404,web项目自带的index.jap却能正常访问,一直找不到原因,后来发现建立放配置文件的文件夹con ...