java获取时间戳单位秒,如何测试给定的时间戳是以秒或毫秒为单位?「建议收藏」

java获取时间戳单位秒,如何测试给定的时间戳是以秒或毫秒为单位?「建议收藏」Assumeagivenvariable,itiscontainingaUNIXtime-stamp,butwhetheritisinsecondsormillisecondsformatisunknown,IwanttoassigntoavariablewhichisinsecondsformatForExample:unkno…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

java获取时间戳单位秒,如何测试给定的时间戳是以秒或毫秒为单位?「建议收藏」

Assume a given variable, it is containing a UNIX time-stamp, but whether it is in seconds or milliseconds format is unknown, I want to assign to a variable which is in seconds format

For Example:

unknown = 1398494489444 # This is millisecond

t = ???

Updated: I understand it is not possible to tell without giving some limitations, so here is it

current_ts – 86400 * 365 < unknown < current_ts

Assume current_ts = current unix timestamp

解决方案

If you convert the maximum timestamp values with x digits in millis you get something like this:

9999999999999 (13 digits) means Sat Nov 20 2286 17:46:39 UTC

999999999999 (12 digits) means Sun Sep 09 2001 01:46:39 UTC

99999999999 (11 digits) means Sat Mar 03 1973 09:46:39 UTC

Can your timestamps be older than 2001? If not i think you’re safe to check whether the number has 13 digits or more – if yes you have milliseconds, if not you have seconds. Of course this will only work until timestamps in seconds will have 13 digits as well, which means timestamps in milliseconds will have 16 digits:

1000000000000000 (16 digits) means Fri Sep 27 33658 01:46:40 but by then i will be living on a planet from the Alpha Centauri system and time standards will probably have changed a bit :)

P.S. you can loosen up the condition to 12 digits or more, if your timestamps can’t go back further than 1973. The condition should only be ok up until:

100000000000000 (15 digits) means Wed Nov 16 5138 09:46:40

because this in seconds will have 12 digits and will overlap with your condition

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/197348.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • angular第一天

    angular第一天

    2022年2月21日
    59
  • 小试 ScriptManager

    小试 ScriptManager1概述ScriptManager控件管理用于MicrosoftASP.NETAJAX页面的客户端脚本。默认情况下,ScriptManager控件将MicrosoftAJAX库的脚本与页面注册到一起,这使脚本可以使用类型系统扩展并支持局部页面输出和Web服务调用。在页面中,必须使用ScriptManager控件来使下列MicrosoftASP.NETAJAX…

    2022年7月13日
    19
  • 知识图谱入门 (七) 知识推理

    知识图谱入门 (七) 知识推理欢迎大家关注我的博客http://pelhans.com/,所有文章都会第一时间发布在那里哦~本节对本体任务推理做一个简单的介绍,并介绍本体推理任务的分类。而后对本体推理的方法和工具做一个介绍。知识推理简介知识推理任务分类所谓推理就是通过各种方法获取新的知识或者结论,这些知识和结论满足语义。其具体任务可分为可满足性(satisfiability)、分类(clas…

    2022年6月12日
    29
  • 直播技术——视频编解码(理论基础)

    直播技术——视频编解码(理论基础)摘自:https://www.cnblogs.com/xkfz007/archive/2012/08/12/2613690.html第1章介绍1.为什么要进行视频压缩?未经压缩的数字视频的数据量巨大存储困难一张DVD只能存储几秒钟的未压缩数字视频。传输困难1兆的带宽传输一秒的数字电视视频需要大约4分钟。2. 为什么可以压

    2022年7月21日
    17
  • 关于 RAID 5 与热备份(Hot Spare)

    关于 RAID 5 与热备份(Hot Spare)关于 RAID5 与热备份 HotSpare 热备份 HotSpare 与 CPU 系统电连接的硬盘 它能替换下系统中的故障盘 与冷备份的区别是 冷备份盘平时与机器不相连接 硬盘故障时才换下故障盘 当一个正在使用的磁盘发生故障后 一个空闲 加电并待机的磁盘将马上代替此故障盘 此方法就是热备用 热备用磁盘上不存储任何的用户数据 最多可以有 8 个磁盘作为热备用磁盘 一个热备用磁

    2026年1月16日
    1
  • 怎么完全卸载赛门铁克_发一个赛门铁克的卸载工具

    怎么完全卸载赛门铁克_发一个赛门铁克的卸载工具===================================WhatisNONAV===================================NONAVisanunsupportedSymantectoolforremovingfilesandregistrykeysfromNortonAntivirus/SymantecAntiviru…

    2022年5月1日
    61

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号