简体   繁体   中英

How to compare Moment.js date?

How to compare Moment.js date? I have JSON in which there is a "date", how can I compare today with what is in the "date"?

My Json:

{
   date: "2020-03-29 17:03:04"
}

My code:

moment(MYJSON).isSame(moment().format('L') // false

在此处输入图片说明

Use moment().isSame() to check if a moment is the same as another moment. The first argument will be parsed as a moment, if not already so.

Passing in month will check month and year. Passing in day will check day, month, and year

Docs: https://momentjscom.readthedocs.io/en/latest/moment/05-query/02-is-same/

 var input = "2020-03-29 17:03:04"; console.log(moment(input).isSame("2020-12-31", "year"));
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM