作者heyyosweet (爱捣蛋)
看板Ajax
标题Re: [问题] javascript 显示现在时间,不足12自动补0
时间Wed Dec 8 23:38:44 2010
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
1F:→ heyyosweet:月份跟日期忘记加了 12/08 23:39
2F:→ mylucky:感谢您,用此法已可正常显示, 感激不尽^^" 12/09 01:18