第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用JavaScript添加/減去日期?

如何使用JavaScript添加/減去日期?

我想讓用戶使用JavaScript輕松地添加和減去日期,以便按日期瀏覽其條目。日期的格式為:“ mm / dd / yyyy”。我希望他們能夠單擊“下一步”按鈕,并且如果日期是:“ 06/01/2012”,則單擊下一步時(shí),它應(yīng)該變成:“ 06/02/2012”。如果他們單擊“上一個(gè)”按鈕,則它應(yīng)變?yōu)椤?05/31/2012”。它需要跟蹤of年,每月的天數(shù)等。有任何想法嗎?使用AJAX從服務(wù)器獲取日期的PS不是一種選擇,這有點(diǎn)滯后,而不是客戶端想要的用戶體驗(yàn)。
查看完整描述

3 回答

?
烙印99

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊

碼:


var date = new Date('2011', '01', '02');

alert('the original date is ' + date);

var newdate = new Date(date);


newdate.setDate(newdate.getDate() - 7); // minus the date


var nd = new Date(newdate);

alert('the new date is ' + nd);

使用Datepicker:


$("#in").datepicker({

    minDate: 0,

    onSelect: function(dateText, inst) {

       var actualDate = new Date(dateText);

       var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1);

        $('#out').datepicker('option', 'minDate', newDate );

    }

});


$("#out").datepicker();

JSFiddle演示


可能會(huì)派上用場(chǎng)的其他東西:


getDate()   Returns the day of the month (from 1-31)

getDay()    Returns the day of the week (from 0-6)

getFullYear()   Returns the year (four digits)

getHours()  Returns the hour (from 0-23)

getMilliseconds()   Returns the milliseconds (from 0-999)

getMinutes()    Returns the minutes (from 0-59)

getMonth()  Returns the month (from 0-11)

getSeconds()    Returns the seconds (from 0-59)


查看完整回答
反對(duì) 回復(fù) 2019-10-18
?
qq_花開(kāi)花謝_0

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊

您需要在javascript Date對(duì)象中使用getTime()和setTime()添加或減去時(shí)間。達(dá)到第1、30、31等個(gè)月的限制時(shí),使用setDate()和getDate()將導(dǎo)致錯(cuò)誤。


使用setTime允許您設(shè)置偏移量(以毫秒為單位),并讓Date對(duì)象計(jì)算其余部分:


var now=new Date();

var yesterdayMs = now.getTime() - 1000*60*60*24*1; // Offset by one day;

now.setTime( yesterdayMs );


查看完整回答
反對(duì) 回復(fù) 2019-10-18
  • 3 回答
  • 0 關(guān)注
  • 557 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)