当前位置:网站首页>Timestamp formatting "recommended collection"
Timestamp formatting "recommended collection"
2022-08-02 18:38:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
一、须知:
1. Pure numeric timestamp minutes2种,一种是10位的,Only the year, month, day, hour, minute, and second are included,也就是说,只精确到秒.一种是13位的,包含毫秒.这2Both are called timestamps,Timestamps are not only accurate to milliseconds.
10The bit timestamp is from1970-01-01到当前的秒数,注意,Not milliseconds,So you need to parse by milliseconds,要 * 1000 13The bit timestamp is from1970-01-01到当前的毫秒数,在java中用Instant对象对应.
2. timestampThe format string is capitalizedSto represent milliseconds.SThe number of bits strictly corresponds to the number of milliseconds,否则报错.If the specification requires precision to the millisecond,Then give the time string,那肯定是3位.给2Bit accurate to less than a millisecond,给4位,The number of milliseconds obtained will also not contain information beyond the milliseconds.
@Test
def tt3(): Unit = {
val dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
//Timestamps and time objects are interchangeable
println(LocalDateTime.parse("2020-04-04 08:08:08.123", dtf).toInstant(ZoneOffset.of("+8")).toEpochMilli) //1585958888123
println(LocalDateTime.ofInstant(Instant.ofEpochMilli(1585958888123L), ZoneOffset.of("+8"))) //2020-04-04T08:08:08.123
//这2个值是一样的,The parsing seconds above,下面的是 * 1000 Post-parse milliseconds
println(LocalDateTime.ofEpochSecond(1585958888L, 0, ZoneOffset.ofHours(8))) //2020-04-04T08:08:08
println(LocalDateTime.ofInstant(Instant.ofEpochMilli(1585958888000L), ZoneOffset.of("+8"))) //2020-04-04T08:08:08
}3. LocalDateTime.ofEpochSecond(1585958888L, 0, ZoneOffset.ofHours(8))Used to convert seconds to a time object.LocalDateTime.ofInstant(Instant.ofEpochMilli(1585958888000L), ZoneOffset.of(“+8”))Used to convert milliseconds to a time object.Epoch的意思是从1970-01-01开始.
二、HiveSupport for timestamps in
Hive并没有提供13Conversion function for bit timestamps,但是load的时候,It will automatically recognize the shape as”2020-04-04 08:08:08.123″This timestamp with milliseconds,It will import normally and display and use normally.
Hive中10Conversion of bit-only numeric timestamps: https://www.cnblogs.com/dcx-1993/p/11359139.html
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/125151.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢
随机推荐
word公式复制到另一个word当中出现图片解决方案
【[USACO06NOV]Corn Fields G】【状压DP】
QueryWrapper method explained
2022 年值得尝试的 7 个 MQTT 客户端工具
怒写400篇AI文章!这群妹子卷疯了…
CefSharp practical demonstration
julia系列6:并行计算
Mysql 查询语句中where字段= '' 作用是什么 ?如何实现多条件查询
如何为项目匹配资源技能和要求?
tiup mirror sign
11.2-HJ86 求最大连续bit数
Qt读取Json文件(含源码+注释)
锁定和并发控制(一)
tiup mirror publish
【学术相关】北大一研究生偷取同门师妹论文发表,作者却挂名给了武大 3 位不知情的学生......
小程序实现手写左右翻页和动态修改横向滚动条位置
Redis进阶之路:深度解析Redis单线程架构,图文并茂不能再清晰了
[LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II
MongoDB 《三》复制集集群搭建实例
synchronized已经不在臃肿了,放下对他的成见之初识轻量级锁







![链表的归并排序[自顶向下分治 || 自低向上合并]](/img/7b/81c5d876567a2017df64e87ee3b478.png)

![【[NOI2001] 炮兵阵地】【状压DP】](/img/ae/6b01b175b0158fb804211931d57c0c.jpg)