Check out a free preview of the full Build a Game Project: Feed-A-Star-Mole course:
The "Unix Time" Lesson is part of the full, Build a Game Project: Feed-A-Star-Mole course featured in this preview video. Here's what you'd learn in this lesson's course:

Brian explains how to use dates in JavaScript to log time.

Get Unlimited Access Now

Transcript from the "Unix Time" Lesson

[00:00:00]
>> Brian Holt: date.now this is going to be a very, very, very useful function for you that you're going to have to get used to. date.now, if I call like that, gives me how many milliseconds it's been since January 1, 1970. For real, that's actually what it does. Why January 1st, 1970?

[00:00:23]
That's called the UNIX time or UNIX Epoch time. Whenever they invented UNIX, they just decided, we're gonna track time since 1970. So every programming language tracks time this way, it's not just JavaScript. So this is gonna be useful for you because every time you call you can see that this is constantly increasing.

[00:00:46]
This is giving me whatever time my computer thinks it is, right? So that means, if I wanna say then equals date.now
>> Brian Holt: And then we'll wait like five more seconds and then I'm going to say, okay, how many seconds has it been since then? I'm gonna say date.now minus then.

[00:01:12]
Right? And I'm going to see that it's been roughly about 12 seconds since I started tracking them, right? So this is how you're going to track how much time has transpired since last time you called the function. You're gonna use date.then and then you're going to minus whatever date.now was back then.