Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created August 24, 2009 07:01
Show Gist options
  • Save Superbil/173710 to your computer and use it in GitHub Desktop.
Save Superbil/173710 to your computer and use it in GitHub Desktop.
計算已經服役天數
<div style=""><script language="javascript">
/* 計算已經服役天數 */
var now = new Date();
var day = new Date(2009,9-1,1);
/* 這個是入伍日期,上面的寫法是:我在 2007 年 10 月 17 入伍 */
day = (now.getTime()- day.getTime())/(24*60*60*1000);
/* 現在時間減去入伍時間,為 Unix 系統時間,毫秒 */
day = Math.ceil(day);
/*傳回指定數字或運算式的最小整數 */
if (day < 0)
document.write("距離國軍Online 登入還有<strong>" + day*-1 + "</strong> 天");
else
document.write("已經在國軍Oline <strong>" + day + "</strong> 天");
</script></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment