开发者

JQuery DateTime - compare days

开发者 https://www.devze.com 2023-03-19 11:29 出处:网络
just wodnering if it\'s possible to compare the difference in days between two dates, I have done this in c# like so, but can it be done in JQuery?

just wodnering if it's possible to compare the difference in days between two dates, I have done this in c# like so, but can it be done in JQuery?

        TimeSpan span = DateTime.Now - LastDate;       

        if (span.Days > 3)
        {

        }
        else
        {
开发者_运维百科
        }

Anyone have any ideas?

Cheers


Here's a javascript function to get the days between 2 dates in javascript, no need for jquery here;

function days_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}
0

精彩评论

暂无评论...
验证码 换一张
取 消