首页 > 解决方案 > Compare date to current month year

问题描述

In one of the API I am using I have a date in the format yyyy-MM-dd hh:mm:ss I am trying compare this date to just the current month and year. How do I just take out the month and year from that date and compare it in AngularJS? I read the AngularJS Documentation for date formats and I can't seem just get the month and year from that format so that I can compare it with the current month and year

标签: angularjs

解决方案


参考momentjs 文档。

请参阅下面的代码片段,

var apidate = moment('2019-01-01 11:31:23', 'YYYY-MM-DD hh:mm:ss'); // API date

console.log("Day="+apidate.date()+ " Year="+apidate.year());

var now = moment(); // current date

console.log("Day="+now.date()+ " Year="+now.year());

// compare day and year of both dates
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>


推荐阅读