> For the complete documentation index, see [llms.txt](https://triplexlab.gitbook.io/vanilla-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triplexlab.gitbook.io/vanilla-js/basics/date/d-day.md).

# D-day 구하기

## D-day 구하기

끝나는 날짜를 설정해서 변수에 담습니다.

```javascript
const shortcode_date = '2020-03-15T24:00:00'  // 끝나는 날짜를 설정
```

### 현재 시간에서 D-day 구해준다.

```javascript
const timeId = setInterval(function() {
    const now = new Date(); 
    const countTo = new Date(shortcode_date);
    const difference = (now - countTo);
    const day = Math.floor(difference/(60*60*1000*24)*1);
    console.log(day)
}, 1000);
```

### 현재 시간에서 를 구해준다.

```javascript
setInterval(function() {
    const now = new Date(); 
    const countTo = new Date(shortcode_date);
    const difference = (now - countTo);
    const hour = Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
    console.log(hour)
}, 1000);
```

### 현재 시간에서 분를 구해준다.

```javascript
setInterval(function() {
    const now = new Date(); 
    const countTo = new Date(shortcode_date);
    const difference = (now - countTo);
    const minute = Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
    console.log(minute)
}, 1000);
```

### 현재 시간에서 초를 구해준다.

```javascript
setInterval(function() {
    const now = new Date(); 
    const countTo = new Date(shortcode_date);
    const difference = (now - countTo);
    const second = Math.floor(((( difference % (60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
    console.log(second)
}, 1000);
```

{% file src="/files/-M2YhfVzWVhUHP94iYED" %}
newDate circle 애니메이션
{% endfile %}
