System,java面试突击第二季

  • This method provides nanosecond precision, but not necessarily

  • nanosecond resolution (that is, how frequently the value changes)

    • no guarantees are made except that the resolution is at least as
  • good as that of {@link #currentTimeMillis()}.

  • Differences in successive calls that span greater than

  • approximately 292 years (263 nanoseconds) will not

  • correctly compute elapsed time due to numerical overflow.

  • The values returned by this method become meaningful only when

  • the difference between two such values, obtained within the sam

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

e

  • instance of a Java virtual machine, is computed.

  • For example, to measure how long some code takes to execute:

  •  {@code
    
  • long startTime = System.nanoTime();

  • // … the code being measured …

  • long estimatedTime = System.nanoTime() - startTime;}

  • To compare two nanoTime values

  •  {@code
    
  • long t0 = System.nanoTime();

  • long t1 = System.nanoTime();}

  • one should use {@code t1 - t0 < 0}, not {@code t1 < t0},

  • because of the possibility of numerical overflow.

  • @return the current value of the running Java Virtual Machine’s

  •     high-resolution time source, in nanoseconds
    
  • @since 1.5

*/

public static native long nanoTime();

翻译下来如下:

返回正在运行的Java虚拟机的高分辨率时间源的当前值,以纳秒计。

该方法可能仅仅用于测量已经逝去的时间,并且与任何其它系统或者挂钟时间概念无关。该返回值表示从某个固定但任意的原点时间(可能在未来,所以值可能是负数)开始的纳秒数。在一个java虚拟机实例中,所有该方法的调用都使用相同的原点;其它虚拟机实例很可能使用不同的源头。

该方法提供了纳秒级别的精度,但是不一定是纳秒级分辨率(也就是该值改变的频率)———— 除非这个分辨率至少和currentTimeMillis()一样好,否则将不会做任何保证。

在跨越大于292年(2的63次方纳秒)左右的连续调用中,这个差值将不能正确地计算已经过去的时间,因为数字溢出。

仅仅只有当在同一java虚拟机实例中获取的两个值之间的差值被计算时,返回值才有意义。

例如,去测量某代码执行花费了多长时间:

long startTime = System.nanoTime();

//…被测量的代码…

long estimatedTime = System.nanoTime() - startTime;

要比较两个nanoTime的值:

long t0 = System.nanoTime();

long t1 = System.nanoTime()。

因为数字溢出的可能性,您应该使用"t1 - t0 < 0",而不是"t1 < t0"(来判断它们的大小,笔者注)。

@return 当前正在运行的java虚拟机的高精度时间资源值,以纳秒为单位。

@since 1.5

System.currentTimeMillis()

/**

  • 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.

  • See the description of the class Date 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();

翻译

返回当前时间(以毫秒为单位)。请注意,虽然返回值的时间单位是毫秒,但是*值的粒度

取决于基础操作系统,并且可能更大。例如,许多操作系统以数十*毫秒为单位测量时间。

  • 有关*“计算机时间”和协调世界时(UTC)之间可能出现的细微差异的讨论,请参见类

  • Date </ code>的描述。

2,解读

currentTimeMillis()

(1)从源码中可以看到,这个方式是一个native方法,该值由底层提供。

(2)该方法可以用来计算当前日期,当前星期几等,与Date的换算非常方便,JDK提供了相关的接口来换算。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
建议阅读本文档的方式 本文档提供详细的目录,建议大家使用电脑阅读。如果大家用手机阅读的话,可以下载一个不错的PDF阅读器,比如 很多人常用的福昕PDF阅读器。 本文档提供详细的目录,大家可以根据自己的实际需要选择自己薄弱的知识章节阅读。 前言 不论是校招还是社招都避免不了各种面试、笔试,如何去准备这些东西就显得格外重要。不论是笔试还是面试都是有 章可循的,我这个“有章可循”说的意思只是说应对技术面试是可以提前准备。 运筹帷幄之后,决胜千里之外!不打毫无准备的仗,我觉得大家可以先从下面几个方面来准备面试: 1. 自我介绍。(你可千万这样介绍:“我叫某某,性别,来自哪里,学校是那个,自己爱干什么”,记住:多说点简 历上没有的,多说点自己哪里比别人强!) 2. 自己面试中可能涉及哪些知识点、那些知识点是重点。 3. 面试中哪些问题会被经常问到、面试中自己改如何回答。(强烈不推荐背题,第一:通过背这种方式你能记住多 少?能记住多久?第二:背题的方式的学习很难坚持下去!) 4. 自己的简历该如何写。 “80%的offer掌握在20%的人手中” 这句话也不是不无道理的。决定你面试能否成功的因素中实力固然占有很大一部 分比例,但是如果你的心态或者说运气不好的话,依然无法拿到满意的 offer。运气暂且不谈,就拿心态来说,千万 不要因为面试失败而气馁或者说怀疑自己的能力,面试失败之后多总结一下失败的原因,后面你就会发现自己会越来 越强大。 另外,大家要明确的很重要的几点是: 1. 写在简历上的东西一定要慎重,这可能是面试官大量提问的地方; 2. 大部分应届生找工作的硬伤是没有工作经验或实习经历; 3. 将自己的项目经历完美的展示出来非常重要。 笔主能力有限,如果有不对的地方或者和你想法不同的地方,敬请雅正、不舍赐教。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值