Re: [問題] javascript 顯示現在時間,不足12自動補0
RightNow = new Date();
alert(
(
RightNow.getMonth()+1)+ "-" +
RightNow.getDate() + "-" +
RightNow.getFullYear() + " " +
(
RightNow.getHours() < 10 ?
'0'+RightNow.getHours() :
RightNow.getHours()
) + ":" +
(
RightNow.getMinutes() < 10 ?
'0'+RightNow.getMinutes() :
RightNow.getMinutes()
) + ":" +
(
RightNow.getSeconds() < 10 ?
'0'+RightNow.getSeconds() :
RightNow.getSeconds()
)
);
※ 引述《mylucky (後來)》之銘言:
: 如題, 想再往業的第一行能顯示目前的日期與時間
: <script language="javascript">
: RightNow = new Date();
: document.write((RightNow.getMonth()+1)+ "-" + RightNow.getDate() + "-" +
: RightNow.getFullYear() + " " + RightNow.getHours() + ":" +
: RightNow.getMinutes() + ":" + RightNow.getSeconds())
: </script>
: 上面是我的程式碼, 上述程式碼顯示出來的時間,
: EX: 12-8-2010 8:10:7
: 現在不知道要怎麼修改, 能夠讓"不足"兩位數的時間數字自動補0
: EX: 12-08-2010 08:10:07 <<---
: 在網路上爬不少文章, 修改了後就變成無法顯示@@"
: 目前只知道說應該是用 RightNow.getxxx < 12 去判斷,
: 各位先進可否協助修正程式碼點醒小弟, 我爬了半天修改出來都是一片空白 @@"
: 感激不盡 ~~
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.97.25
→
12/08 23:39, , 1F
12/08 23:39, 1F
→
12/09 01:18, , 2F
12/09 01:18, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章