Skip to content

Commit

Permalink
added getTime and now method in tips
Browse files Browse the repository at this point in the history
  • Loading branch information
nurrony committed Feb 20, 2016
1 parent 8510c29 commit e488011
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions _posts/en/2016-02-15-extract-unix-timestamp-easily.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```

0 comments on commit e488011

Please sign in to comment.