2014-01-17 58 views

回答

0

您可以使用下面的代碼。 用結束日期編輯名爲targetDate的變量。

function doGet() { 
    var today = new Date(); 
    var targetDate = new Date(2014, 1, 25) // - February 25th of 2014 
    today.setHours(0,0,0,0); 

    var ui = UiApp.createApplication(); 
    ui.add(ui.createLabel(calcDate(today, targetDate))); 
    return ui; 
} 


function calcDate(date1,date2) { 
    var diff = Math.floor(date2.getTime() - date1.getTime()); 
    var day = 1000* 60 * 60 * 24; 

    var days = Math.floor(diff/day); 
    var months = Math.floor(days/31); 
    var years = Math.floor(months/12); 

    var message = days + " days " ; 
    message += months + " months "; 
    message += years + " years left \n"; 

    return message 
} 

現場版可以找到here

+0

此代碼是開始。如果將其嵌入到側邊欄並顯示實時倒計時,可以對gdoc進行改進。爲此,您需要使用htmlService(使用setInterval)而不是像這樣完成的uiservice。 –

0

只是要注意;我盲目地改變了制定目標日期的數量,但要小心,從0開始的月數不是1. 0是1月,1月是2月等。