【问题标题】:How to get specific month on AngularJS如何在 AngularJS 上获取特定月份
【发布时间】:2021-01-26 05:05:53
【问题描述】:

如何从 angularJS 的后端获取特定日期月份

我希望添加这样的内容:

 var curMonth = new Date().getMonth();
      var monthData = vm.paymentsData[0].date.Date().getMonth();
      if (curMonth == monthData) {
           console.log ("Same Month");
      }

我遇到错误:

var monthData = vm.paymentsData[0].date.Date().getMonth();

上面写着:

angular.js:14328 TypeError: vm.paymentsData[0].date.Date is not a function

谢谢

Data from the backend

【问题讨论】:

  • “我希望添加这样的内容:” 那么你的问题是什么??
  • 如果不是新日期,如何获取月份。我在 angular.js:14328 TypeError 上遇到错误:vm.paymentsData[0].date.Date is not a function

标签: angularjs date


【解决方案1】:

我觉得你的代码应该写成这样:

var curMonth = new Date().getMonth();
// this maybe a string .. and you cannot call Date() function in that way.
var monthData = vm.paymentsData[0].date;
// Date function should be called this way.
var monData = (new Date(monthData)).getMonth();
if (curMonth == monData) {
    console.log ("Same Month");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多