angularjs - 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
解决方案
请参阅下面的代码片段,
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>
推荐阅读
- python - 向数据框添加总计和计数行
- .net - netcore:期待 NU1701 但我什么也没得到
- flutter - 如何在小部件中使用条件?
- java - 片段中的 onActivityResult 不会更新 ListView
- amazon-web-services - Kafka 侦听器错误:2 个分区的领导代理没有匹配的侦听器
- tensorflow - 如何使用 TPU 诊断内存不足错误
- node.js - 我应该从哪里连接到 aws?nodejs服务器?还是角度客户端?
- wordpress - Wordpress 永久链接 nginx 中的未授权错误
- mongodb - 别名 mongo compass 中的字段名称
- python - 7zip - 指定递归模式和压缩类型