﻿function dealTime(timeArea) {
    var current = new Date(),
        yC = current.getFullYear(),
        mC = current.getMonth() + 1,
        dC = current.getDate(),
        totalTimeC = 1000 * current.getSeconds() * current.getMinutes() * current.getHours();

    $(timeArea).each(function() {
        var TimeDate_Created = $.trim($(this).text()).split(" "),
            TimeArr = TimeDate_Created[1].split(":"),
            DateArr = TimeDate_Created[0].split("/"),
            sDB = parseInt(TimeArr[2]),
            mtDB = parseInt(TimeArr[1]),
            hDB = parseInt(TimeArr[0]),
            dDB = parseInt(DateArr[2]),
            mdDB = parseInt(DateArr[1]),
            yDB = parseInt(DateArr[0]);
        var totalTimeDB = 1000 * sDB * mtDB * hDB;
        if (yC === yDB) {
            if (mC === mdDB) {
                if (dC === dDB) {
                    if (current.getHours() === hDB) {
                        if (current.getMinutes() === mtDB) {
                            $(this).text((current.getSeconds() - sDB) + "秒前");
                        }
                        else {
                            $(this).text((current.getMinutes() - mtDB) + "分钟前");
                        }
                    }
                    else {
                        $(this).text((current.getHours() - hDB) + "小时前");
                    }
                }
                else {
                    $(this).text((dC - dDB) + "天前");
                }
            }
            else {
                if (dC < dDB) {
                    (new Date(yC, mC - 1, dC)) - (new Date(yDB, mdDB - 1, dDB));
                    $(this).text(((new Date(yC, mC - 1, dC)) - (new Date(yDB, mdDB - 1, dDB))) / 1000 / 60 / 60 / 24 + "天前");
                } else {
                    $(this).text((mC - mdDB) + "个月前");
                }
            }
        }
        else {
            //$(this).text((yC - yDB) + "年前");
            (new Date(yC, mC - 1, dC)) - (new Date(yDB, mdDB - 1, dDB));
            $(this).text(((new Date(yC, mC - 1, dC)) - (new Date(yDB, mdDB - 1, dDB))) / 1000 / 60 / 60 / 24 + "天前");
        }

    });
}

$(function() {
    dealTime(".timeFromDB");
    $(".lg_hlp").slideDown("normal");
});
