Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Dec 11, 2020
1 parent 8e5fc87 commit 43f60a1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions docs/rules/prefer-date-now.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
# Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch.
# Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch

<!-- More detailed description. Remove this comment. -->
[`Date.now()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) is shorter and nicer.

This rule is fixable.

## Fail

```js
const foo = 'unicorn';
const foo = new Date().getTime();
```

```js
const foo = new Date().valueOf();
```

```js
const foo = +new Date;
```

```js
const foo = Number(new Date());
```

```js
const foo = new Date() * 2;
```

## Pass

```js
const foo = '🦄';
const foo = Date.now();
```

```js
const foo = Date.now() * 2;
```

0 comments on commit 43f60a1

Please sign in to comment.