JavaScript日期和时间简介

It’s perhaps easiest to think of JavaScript time existing in four parts:

可能最容易想到存在四个部分JavaScript时间:

  1. Microsecond time from the internal system clock, used in the Web Performance API.

    Web Performance API中使用的距内部系统时钟的微秒时间。
  2. The “system-level” time of milliseconds and Unix time, on which the others ultimately depend.

    其他人最终依赖的“系统级”时间(毫秒)和Unix时间。
  3. Timers: setTimeout and setInterval, which typically set delays of milliseconds to seconds.

    计时器: setTimeoutsetInterval ,通常将毫秒延迟设置为秒。

  4. “Human-readable” date formats, such as “January 1, 2015”.

    “人类可读”的日期格式,例如“ 2015年1月1日”。

JavaScript doesn’t make these distinctions itself: with the exception of the Web Performance API, all time in JavaScript is derived from a standard known as the Unix epoch.

JavaScript本身并没有做出这些区分:除Web Performance API之外,JavaScript中的所有时间都源自一个称为Unix时代的标准。

JavaScript时间约定 (JavaScript time conventions)

Most every expression of time on a digital device is derived from the microsecond “tick-tock” of a chip, which keeps track of the so-called Unix epoch: the number of milliseconds that have passed since midnight, January 1, 1970 UCT. You can see this number for yourself in a browser: open up a console window and type:

数字设备上的大多数时间表达都来自芯片的微秒“滴答”声,它跟踪所谓的Unix时期:自1970年1月1日午夜以来经过的毫秒数。 您可以在浏览器中自己看到此数字:打开控制台窗口,然后键入:

Date.now()

The number you’ll get back after hitting Enter look something like this: > 1413067397613

按下Enter键后您会得到的号码如下所示:> 1413067397613

This ever-increasing number, also known as the Unix timestamp, is the means by which most computer time is measured, with everything else – time in the future, past, and the difference between dates – resolved by conversion into this format, after taking into account other factors such as time zones and leap seconds.

这个不断增加的数字(也称为Unix时间戳)是用来测量大多数计算机时间的方法,其他所有信息(将来,过去的时间以及日期之间的差额)都可以通过转换为这种格式来解决,考虑其他因素,例如时区和leap秒。

High resolution (1 millionth of a second) timing is also available via the Web Performance API, although that is excessive for most purposes.

还可以通过Web Performance API获得高分辨率(百万分之一秒)的定时,尽管对于大多数目的来说,这是多余的。

This series will explore JavaScript time from the top down, starting with the human-readable formats and working to the micro level. We’ll start by making a simple clock, progressing to more advanced examples.

本系列将从上至下探索JavaScript时间,从人类可读的格式开始,再到微观层次。 我们将首先制作一个简单的时钟,然后继续进行更高级的示例。

翻译自: https://thenewcode.com/940/Introduction-to-Dates-and-Times-in-JavaScript

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值