To look for the methods to display a simple date in HTML.I have searched for many website, most ppl use jquery plugin, and i have tried some and find "not work"
Why make that so complicated ? So i start simple javascript to do that:
---------------- Method 1-------------
JavaScript code:
<script language="JavaScript">HTML code:
var currentTime = new Date();
var year = currentTime.getFullYear();
var mouth = currentTime.getMonth();
var date = currentTime.getDate();
thisMouth.innerHTML=mouth;
thisDate.innerHTML=date;
thisYear.innerHTML=year;
</script>
<span id="thisDate">dd</span>-<span id="thisMouth">mm</span>-<span id="thisYear">yyyy</span>Use JavaScript default function to get the current time, store that into valuable,
and then use JavaScript to change the text inside the html <sapn> tab with the specified id name.
Result :
17/6/2013---------------Extend from method 1----------------
Start from same coding
if the date is 6, display 06
JavaScript Code:
<script language="JavaScript">HTML Code:
var currentTime = new Date();
var year = currentTime.getFullYear();
var mouth = currentTime.getMonth();
var date = currentTime.getDate();
if (mouth/10 >1){ thisMouth.innerHTML=mouth; }else { thisMouth.innerHTML="0"+mouth; }
if (date/10 >1){ thisDate.innerHTML=date; }else { thisDate.innerHTML="0"+date; }
thisYear.innerHTML=year;
</script>
<span id="thisDate">dd</span>-<span id="thisMouth">mm</span>-<span id="thisYear">yyyy</span>Result:
17/06/2013
No comments :
Post a Comment