Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript에서 오늘 날짜에서 날짜를 빼는 방법은 무엇입니까?

<시간/>

new Date().getDate()의 도움으로 currentDate를 사용해야 합니다. 구문은 다음과 같습니다 -

var anyVariableName=yourCurrentDate - yourSubstractDateOfCurrentMonth;

예시

var currentDate=new Date().getDate();var substractDate=new Date("2020-07-01").getDate();const numberOfDaysInCurrentMonthOnly =currentDate-substractDate;console.log(numberOfDaysInCurrentMonthOnly); 

참고

오늘 날짜는 2020-07-28일입니다.

위의 프로그램을 실행하려면 다음 명령을 사용해야 합니다 -

노드 fileName.js.

여기에서 내 파일 이름은 demo129.js입니다.

PS C:\Users\Amit\JavaScript-code> 노드 demo129.js27