, , , .
, : Moment.js.
, :
var days = moment().diff("2015-06-02", "days");
, , , .. - .
. DEMO.
:
:
var ago = moment.duration(moment().diff("2015-06-05")).humanize() + " ago";
, :
"15 days ago""13 hours ago""5 years ago"
countedBannedDays.innerHTML, . . DEMO.
, banSelectedDate , - DOM , :
var banDate = $find("<%= rdtpBan.ClientID %>");
var TodayDate = new Date();
var today = new Date();
var todayFormat = new Date(today.getMonth() + 1 + "/" + today.getDate() + "/" + today.getFullYear());
var banSelectedDate = banDate.get_selectedDate();
var one_day = 1000 * 60 * 60 * 24;
var countedDays = (Math.ceil(todayFormat - banSelectedDate) / one_day);
:
var banDate = $find("<%= rdtpBan.ClientID %>");
var banSelectedDate = banDate.get_selectedDate();
var countedDays = moment().diff(banSelectedDate, "days");
:
var countedDays = moment().diff(banSelectedDate, "days");
, , , , , - .
:
. .
With good libraries available to handle such common tasks, we don’t need to write complex code with many potential problems, such as those that you had here. Reusing code not only avoids potential problems, but also makes your own code much more convenient.
source
share