如何顯示部落格已開張多久 - 部落格
By Liam
at 2011-02-16T13:26
at 2011-02-16T13:26
Table of Contents
為了解決日跟月有時會變負的問題
將jlhc大的script加了一小段判斷式
雖然很粗糙而且不是非常準確,不過省下了太複雜的算式
<div id="createDays"></div>
<script type="text/javascript">
var today = new Date();
var createYear = new Date(2007,04,03);
var dd = today.getDate() - createYear.getDate() + 1;
var mm = today.getMonth() - createYear.getMonth();
var yy = today.getFullYear() - createYear.getFullYear();
if (dd<0){
dd=dd+30;
mm=mm-1;
}
if (mm<0){
yy=yy-1;
mm=mm+12
}
document.getElementById('createDays').innerHTML = "This blog is " + yy + " years, "
+ mm + " months, and " + dd + " days old.";
</script>
※ 引述《jlhc (阿之)》之銘言:
: <div id="createDays"></div> //createDays 可以用css修改其樣式
: <script type="text/javascript">
: var today = new Date(); //今天日期
: var createYear = new Date(2011,01,01); //年/月/日, 月份請減1
: var yy = today.getFullYear() - createYear.getFullYear(); // 計算年
: var mm = today.getMonth() - createYear.getMonth(); //計算月
: var dd = today.getDate() - createYear.getDate() + 1; //計算天, 加上今天
: // 輸出的內容可依照喜好設定輸出的格式
: document.getElementById('createDays').innerHTML = "部落格開張 " + yy + " 年 "
: + mm + " 月 " + dd + " 天";
: </script>
--
┌───────────────────┐
│Tosh[ism] http://toshism.blogspot.com/│
└───────────────────┘
--
將jlhc大的script加了一小段判斷式
雖然很粗糙而且不是非常準確,不過省下了太複雜的算式
<div id="createDays"></div>
<script type="text/javascript">
var today = new Date();
var createYear = new Date(2007,04,03);
var dd = today.getDate() - createYear.getDate() + 1;
var mm = today.getMonth() - createYear.getMonth();
var yy = today.getFullYear() - createYear.getFullYear();
if (dd<0){
dd=dd+30;
mm=mm-1;
}
if (mm<0){
yy=yy-1;
mm=mm+12
}
document.getElementById('createDays').innerHTML = "This blog is " + yy + " years, "
+ mm + " months, and " + dd + " days old.";
</script>
※ 引述《jlhc (阿之)》之銘言:
: <div id="createDays"></div> //createDays 可以用css修改其樣式
: <script type="text/javascript">
: var today = new Date(); //今天日期
: var createYear = new Date(2011,01,01); //年/月/日, 月份請減1
: var yy = today.getFullYear() - createYear.getFullYear(); // 計算年
: var mm = today.getMonth() - createYear.getMonth(); //計算月
: var dd = today.getDate() - createYear.getDate() + 1; //計算天, 加上今天
: // 輸出的內容可依照喜好設定輸出的格式
: document.getElementById('createDays').innerHTML = "部落格開張 " + yy + " 年 "
: + mm + " 月 " + dd + " 天";
: </script>
--
┌───────────────────┐
│Tosh[ism] http://toshism.blogspot.com/│
└───────────────────┘
--
Tags:
部落格
All Comments
Related Posts
噗浪當掉了嗎?
By Edward Lewis
at 2011-02-15T23:44
at 2011-02-15T23:44
CSS更改字型設定
By Margaret
at 2011-02-15T18:59
at 2011-02-15T18:59
Re: PTT Blog板友簽到簿(PTTBlogRolling!)
By Edwina
at 2011-02-15T11:59
at 2011-02-15T11:59
朋友邀請數
By Cara
at 2011-02-15T02:24
at 2011-02-15T02:24
Re: PTT Blog板友簽到簿(PTTBlogRolling!)
By Iris
at 2011-02-14T21:02
at 2011-02-14T21:02