Laurentiu Stamate
Laurentiu Stamate

Reputation: 707

Implications of setting cookie expire time

I think this is a matter of personal choice, but is it any difference in performance or style when setting cookie expire time like this:

var expires = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365);

or like this:

var expires = new Date(new Date().getTime() + 31536000000); // one year in milliseconds

Upvotes: 0

Views: 47

Answers (1)

Pezetter
Pezetter

Reputation: 2862

Well as far as style would go, nested date objects are already kind of weird, regardless of doing the math during execution or not.

The performance is negligible as well.

Heres my recommedation:

var expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);

This makes it pretty obvious that you're simply adding a year to the current date.

Upvotes: 1

Related Questions