MozTW 討論區 https://forum.moztw.org/ |
|
時間顯示問題 https://forum.moztw.org/viewtopic.php?f=2&t=7295 |
第 1 頁 (共 1 頁) |
發表人: | ice [ 2005-03-26, 15:52 ] |
文章主題 : | 時間顯示問題 |
代碼: <script language="JavaScript"> <!-- document.write('<div align="center"><font size="2">'); document.write("<span id='clock'></span>"); var now,year,month,date,hours,minutes,seconds,timeValue; function showtime(){ now = new Date(); date = now.getDate(); month= now.getMonth() + 1; year= now.getYear(); hours = now.getHours(); minutes = now.getMinutes(); seconds = now.getSeconds(); timeValue = ((year > 2055) ? year + 1900 : year) + "年 "; timeValue += ((month > 12) ? month - 12 : month) + "月 "; timeValue += ((date > 31) ? date - 31 : date) + "日 "; timeValue += ((hours > 12) ? hours - 12 : hours) + "點 "; timeValue += ((minutes < 10) ? " 0" : " ") + minutes + "分 "; timeValue += ((seconds < 10) ? " 0" : " ") + seconds + "秒 "; timeValue += (hours >= 12) ? "下午 " : "上午 "; clock.innerHTML = timeValue; setTimeout("showtime()",100); } showtime(); document.write('</font></div>'); //--> </script> 代碼在IE下是正常的 顯示後, 年份變成105年 下面代碼如果拿掉 > 2055 火狐就正常, 但IE變 3905年 代碼: timeValue = ((year > 2055) ? year + 1900 : year) + "年 ";
試問是哪個瀏覽器的錯誤 |
發表人: | 風痕影 [ 2005-03-27, 02:06 ] |
文章主題 : | |
其實按照標準,getYear()顯示105年 是正常的 請使用getFullYear()喔~^^ |
發表人: | ice [ 2005-03-27, 02:27 ] |
文章主題 : | |
風痕影 寫: 其實按照標準,getYear()顯示105年 是正常的
請使用getFullYear()喔~^^ 謝謝 以照您的方法修正了 |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |