> For the complete documentation index, see [llms.txt](https://april.gitbook.io/learning-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://april.gitbook.io/learning-js/untitled/15.10.md).

# 15.10 날짜 연산

### 빼기

```javascript
const msDiff = d2 - d1;
const daysDiff = msDiff/1000/60/60/24
```

### 정렬&#x20;

```javascript
const dates = [];

// 랜덤으로 날짜 생성
const min = new Date(2017, 0, 1).valueOf();
const delta = new Date(2020, 0, 1).valueOf() - min;

for (let i=0; i<10; i++)
    dates.push(new Date(min + delta*Math.random()));
    
dates.sort((a, b) => b - a);
dates.sort((a, b) => a - b);
```
