Re: [問題] javascript 顯示現在時間,不足12自動補0

看板Ajax作者 (愛搗蛋)時間14年前 (2010/12/08 23:38), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串2/3 (看更多)
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
文章代碼(AID): #1C_wQ9ZG (Ajax)
文章代碼(AID): #1C_wQ9ZG (Ajax)