Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
日期
99
271,821
年),也可以表示遥远的未来(公元
275,760
年)。
调用
Date.getTime()
方法可以获取毫秒数
两个
Date
对象仅当完全一致时才相等,一直延续到毫秒。两个表示同一日期的
Date
对象,如果时间部分不同,也是不相等的。这可能导致问题,因为你可能并不
知道
Date
对象包含时间信息。创建表示今天的
Date
对象(
4.1
节)时经常遇到这
个问题。
为了避免这个问题,可以使用
Date.setHours()
法去掉时间信息。不要被这个方
法的名称迷惑了,其实它最多可以接受四个参数,分别设定时分秒和毫秒。如果想
创建一个只含日期的
Date
对象,把这些组成部分都设为
0
const
today =
new
Date();
//
再为当前日期创建一个副本
//
日期没变,但是时间可能已经走到下一毫秒了
const
todayDifferent =
new
Date();
//
可能为真,也可能为假,取决于超出你控制的计时因素
console.log(today.getTime() === todayDifferent.getTime());
//
去掉所有时间信息
todayDifferent.setHours(0,0,0,0);
today.setHours(0,0,0,0);
//
始终为真,因为两个实例的时间都去掉了
console.log(today.getTime() === todayDifferent.getTime());
4.4.4
参考
关于日期的更多数学运算,见
4.5
节和
4.3 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript

JavaScript

T. J. Crowder
JavaScript

JavaScript

David Flanagan
JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov

Publisher Resources

ISBN: 9787519869601