当前位置: 首页 > news >正文

网站建设实现后台数据导出excel/网站的网络推广

网站建设实现后台数据导出excel,网站的网络推广,有限公司英文,湖南网站建设公司排名2019独角兽企业重金招聘Python工程师标准>>> 1、问题 java 中,new Date() 方法,获取的时间,究竟与当前的系统时间有什么关联?简单的时刻对应关系吗? 2、测试环境 版本:jdk1.8.0_131主方法: publ…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1、问题

java 中,new Date() 方法,获取的时间,究竟与当前的系统时间有什么关联?简单的时刻对应关系吗?

2、测试环境

  • 版本:jdk1.8.0_131
  • 主方法:
    public static void main(String[] args) throws InterruptedException {SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");int i = 0;while(true){System.out.println(i + "\t" +dateFormat.format( new Date() ) );i++;Thread.sleep(2000);}
    }
    

3、更新时间前

更新时间前

如上图所示,控制台输出的时间,与当前的系统时间一致。

4、更新时间后

保持该main方法一直在运行(不中断,一直在死循环中), 利用win10下的时间设置,更改系统时间后

更新时间后

如上图所示,控制台输出的时间,依然以更新时间前的为基准进行输出。

5、代码溯源

  • Date.java
package java.util;
public class Date/*** Allocates a <code>Date</code> object and initializes it so that* it represents the time at which it was allocated, measured to the* nearest millisecond.** @see     java.lang.System#currentTimeMillis()*/public Date() {this(System.currentTimeMillis());}
}
  • System.java
package java.lang;
public final class System {/*** Returns the current time in milliseconds.  Note that* while the unit of time of the return value is a millisecond,* the granularity of the value depends on the underlying* operating system and may be larger.  For example, many* operating systems measure time in units of tens of* milliseconds.** <p> See the description of the class <code>Date</code> for* a discussion of slight discrepancies that may arise between* "computer time" and coordinated universal time (UTC).** @return  the difference, measured in milliseconds, between*          the current time and midnight, January 1, 1970 UTC.* @see     java.util.Date*/public static native long currentTimeMillis();
}

6、分析

现象:JVM 在某一时刻,获取当前系统时间,同时内部维护该时间(或者说时刻更为准确),后续所有的时间操作,均以此时刻为基准。

由于不确定该时刻是JVM启动时,还是调用 new Date() 方法时;同时为了排除SimpleDateFormat相关方法故继续测试。

7、 继续测试1

更新测试主方法:

  • 要点:确定该时刻,同时排除SimpleDateFormat相关方法影响
public static void main(String[] args) throws InterruptedException {int i = 0;System.out.println("开始---" );Thread.sleep(10000);System.out.println("正式输出---" );while(true){System.out.println(i + "\t" + new Date() );i++;Thread.sleep(2000);}
}

说明:在Thread.sleep(10000) ,利用这段时间(10秒),更新系统时间

分析与继续测试

如上图,更新系统时间前,JVM进程已经启动。

分析与继续测试

如上图,利用这段时间(10秒),更新系统时间,此时,控制台输出的时间,以更新后的时间为基准进行输出。

8、继续测试2

现象:确定不是在 JVM启动时,内部维护该时刻。

但是依然不确定该时刻是调用 new Date() 方法时,还是调用 **System.currentTimeMillis()**时(参见 5、代码溯源 部分 ),故继续测试。

更新测试主方法:

  • 要点:在调用new Date()前,先行调用System.currentTimeMillis() 方法。
     public static void main(String[] args) throws InterruptedException {int i = 0;System.out.println("开始---" );System.out.println("当前系统时间对应的毫秒数:" + System.currentTimeMillis());Thread.sleep(10000);System.out.println("正式输出---" );while(true){System.out.println(i + "\t" + new Date() );i++;Thread.sleep(2000);}
    }
    

测试方法同上一部分,即:

利用这段时间(10秒),更新系统时间.

分析与继续测试

现象:该时刻不以调用 System.currentTimeMillis() 时为基准。

9、 分析

System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMillis()); 因为Date类还有构造Date(long date),用来计算long秒与1970年1月1日之间的毫秒差。得到了这个毫秒数,我们自己也可以算起现在的年月日周时

上述文字,参考:JAVA获取当前时间System.currentTimeMillis()_百度经验

10、猜想

new Date()第一次执行时,获取当前系统时间,同时内部维护该时间(或者说时刻更为准确),后续所有的时间操作,均以此时刻为基准。

继续查阅Date.java 方法

private transient long fastTime;public Date() {this(System.currentTimeMillis());
}
public Date(long date) {fastTime = date;
}

转载于:https://my.oschina.net/u/3136014/blog/1570053

http://www.lbrq.cn/news/808759.html

相关文章:

  • html5做音乐网站/2021十大网络舆情案例
  • 建立个人网站的成本/seo优化网站技术排名百度推广
  • 外贸网站制作推广公司/推广方案
  • 熊掌号怎么做网站跳转链接/网站统计器
  • 好sf123网站123/怎么引流到微信呢
  • 企业单位网站怎么做/职业培训学校加盟合作
  • 2017我们一起做网站/百度账号管理
  • 太月星网站建设程序开发/个人博客模板
  • 唐山哪里有建设网站/seo优化排名教程
  • 做网络的网站很重要吗/站长工具关键词
  • 手机设计房子的软件3d下载/信息流广告优化师培训
  • wordpress幻灯片插件怎么用/而的跟地seo排名点击软件
  • wordpress拉黑用户/青岛招聘seo
  • 外贸网站开发多少钱/百度网页高级搜索
  • 网站建设需要考哪些证/关键词排名优化软件
  • 做网站是干什么的/百度指数关键词
  • 广州市研发网站建设平台/网站建设培训
  • qq刷赞网站怎么做的/广州seo公司排名
  • 大连手机自适应网站建设/it行业培训机构哪个好
  • 长沙天津网站建设/百度seo可能消失
  • 免费网站建设讯息/网站流量查询网站统计查询
  • 中网互联网站建设/免费学生html网页制作成品
  • 网站qq统计/网络推广员招聘
  • 万网制作网站吗/广州最新新闻事件
  • 网页的首页/谷歌seo优化排名
  • 网站空间公司/百度平台客服电话是多少
  • 如何从客户网站开发客户/云搜索引擎入口
  • 怎么用ps做网站ui/查企业信息查询平台
  • 网站文件夹结构/厦门百度seo排名
  • 汕尾招聘 网站建设合伙人/百度联系电话
  • 【跨国数仓迁移最佳实践3】资源消耗减少50%!解析跨国数仓迁移至MaxCompute背后的性能优化技术
  • MOGA(多目标遗传算法)求解 ZDT1 双目标优化问题
  • GaussDB 查看会话连接数
  • 最新!Polkadot 更新 2025 路线图
  • 15-C语言:第15天笔记
  • window显示驱动开发—Direct3D 11 视频设备驱动程序接口 (DDI)