Mattis
Mattis

Reputation: 5096

Javascript Date getTime() code snippet with mysterious additional characters

<script language="JavaScript">
var t = new Date();
t.getTime() + -864e5;
</script>

What is that funky code after the "+" at the end of the second line doing?

It is probably made to be hard to understand, since I suspect it's one of the ways they try to protect themselves against scraping.

Upvotes: 14

Views: 7312

Answers (4)

cocco
cocco

Reputation: 16706

It is a valid JavaScript number that represents the number of milliseconds in a 24 hour day.

1000*60*60*24 or 86400000 or 864e5

Upvotes: 28

e3495026
e3495026

Reputation: 79

864e5 is a valid JavaScript number that represents the number of milliseconds (a millisecond is 1/1000'th of a second) in a 24 hour day.

1000*60*60*24 = 86400000 or using exponential notation 864e5

Upvotes: 2

mynetx
mynetx

Reputation: 898

-864e5 means "minus 1 day". So the JavaScript is really getting the date/time 24 hours ago.

Upvotes: 4

Shade
Shade

Reputation: 785

It looks like the + -864e5 is offsetting the time 1 day into the past.

Its true its not very readable, or makes much sense to people looking at it for a first time, but there isn't really any other way in bare js (at this point).

Upvotes: 1

Related Questions