diff --git a/_posts/en/2016-02-15-extract-unix-timestamp-easily.md b/_posts/en/2016-02-15-extract-unix-timestamp-easily.md index 4ff2dfe8..613d628d 100644 --- a/_posts/en/2016-02-15-extract-unix-timestamp-easily.md +++ b/_posts/en/2016-02-15-extract-unix-timestamp-easily.md @@ -11,12 +11,27 @@ categories: - en --- -We frequently need to calculate with unix timestamp. I think this is the most easiest way to grab the unix timestamp in Javascript. You just need to add a `+` sign when declaring a `Date` object like below +We frequently need to calculate with unix timestamp. There are several ways to grab the timestamp. For current unix timestamp easiest and fastest way is +```js +const timestamp = Date.now(); +``` +or +```js +const timestamp = new Date().getTime(); +``` + +To get unix timestamp of a specific date pass `yyyy-mm-dd` as a parameter of `Date` constructor. For example +```js +const timestamp = new Date('2012-06-08').getTime() +``` + +If you like magic, just add a `+` sign when declaring a `Date` object like below ```js const timestamp = +new Date() ``` -To get unix timestamp of a specific date pass `yyyy-mm-dd` as a parameter of `Date` constructor. For example +or for specific date + ```js const timestamp = +new Date('2012-06-08') ``` \ No newline at end of file