From abcf76fd7d5b10bdf71e38a014551bc0c71220d9 Mon Sep 17 00:00:00 2001 From: Rayon Date: Wed, 28 Nov 2018 22:12:53 +0530 Subject: [PATCH] Added polyfill (#25130) Added polyfill for legacy browsers --- guide/english/javascript/get-timestamp/index.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guide/english/javascript/get-timestamp/index.md b/guide/english/javascript/get-timestamp/index.md index c9000aa1e3..6e5fc4e842 100644 --- a/guide/english/javascript/get-timestamp/index.md +++ b/guide/english/javascript/get-timestamp/index.md @@ -8,3 +8,13 @@ You can easily convert the timestamp to seconds like this: `Math.floor(Date.now( If your browser does not support `Date.now()`, you can use `new Date().getTime()` to get the timestamp in milliseconds. Unix Timestamp is number of seconds elapsed since 01/01/1970, 00:00:00 UTC. The Unix timestamp will break on 01/19/2038. + +### Polyfill +For older browsers, we can use: +```js +if (!Date.now) { + Date.now = function now() { + return new Date().getTime(); + }; +} +```