转载自: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. (转)SQLServer_十步优化SQL Server中的数据访问一

    原文地址:http://tech.it168.com/a2009/1125/814/000000814758_all.shtml 第一步:应用正确的索引 我之所以先从索引谈起是因为采用正确的索引会使生 ...

  2. 恭喜PBD终于有了自己的物理解释和模型

    之前的position based dynamic 总给人一种野路子的感觉,没有物理意义,没有对应的物理模型一切基于几何的方法. 感觉就是犀稀里哗啦将一堆堆约束按梯度方向迭代解算. 最新muller的 ...

  3. Linux中常用目录作用

    Linux一般相应的文件都会会放在相应的目录下.这样更有利于文件的查找. 1.可以在家目录root或home,以及temp目录下随便放东西. 2.根目录下的bin和sbin,usr目录下的bin和sb ...

  4. css修改整个项目的滚动条样式

    在项目中,滚动条不可避免的药出现.设置统一规范的滚动条也是必然.用一个独立的css文件即可修改整个项目中的滚动条样式 . scrollBar.css: /* 滚动条有滑块的轨道部分 */ ::-web ...

  5. setsockopt详解

    Socket描述符选项[SOL_SOCKET] #include <sys/socket.h>  int setsockopt( int socket, int level, int op ...

  6. mongo 索引 安全、备份与恢复

    一.索引 创建大量数据 for(i=0;i<100000;i++){ db.t1.insert({name:"test"+i,age:i}) } 数据查找性能分析 db.t1 ...

  7. mysql 动态行转列

    表结果:create table user( id int , username ), create_time datetime, type int ) insert into user (`id`, ...

  8. Unable to compile class for JSP 的可能原因

    浏览器访问web jsp文件,导致500-Unable to compile class for JSP 的原因. 原因一:查看网上的方法,说很可能的原因是tomcat版本比JDK的版本要低导致的.所 ...

  9. 验证demo

    // chenwenjun.cpp : 定义控制台应用程序的入口点.//#include "stdafx.h"#include <iostream>#include & ...

  10. Springboot admin 发送邮件失败:com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user

    发邮件已经是老生常谈了,今天又遇到了,而且又出了各种问题.我晕哦. 我的配置是: spring.mail.host=smtp..com spring.mail.username=klxxxx spri ...