Javascript Date: next month

后端 未结 8 1422
情深已故
情深已故 2020-11-28 10:01

I\'ve been using Javascript\'s Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected

相关标签:
8条回答
  • 2020-11-28 10:26

    ah, the beauty of ternaries:

    const now = new Date();
    const expiry = now.getMonth() == 11 ? new Date(now.getFullYear()+1, 0 , 1) : new Date(now.getFullYear(), now.getMonth() + 1, 1);
    

    just a simpler version of the solution provided by @paxdiablo and @Tom

    0 讨论(0)
  • 2020-11-28 10:30

    try this:

    var a = screen.Data.getFullYear();
    var m = screen.Data.getMonth();
    var d = screen.Data.getDate();
    
    m = m + 1;
    screen.Data = new Date(a, m, d);
    
    if (screen.Data.getDate() != d)
    screen.Data = new Date(a, m + 1, 0);
    
    0 讨论(0)
提交回复
热议问题