日期书签需要在单位数月份和日期上前导零
我有一个小书签,用于检查每日日志文件。 然而,我使用的书签仅以个位数提供月份和日期,但日志文件使用两位数。
例如我的书签提供: http://url/log/2009-5-4_localcontrol-story.log, 而日志文件实际上位于: http://url/log/2009-05-04_localcontrol-story.log
下面是我当前的代码:
javascript:d=new%20Date();window.open("http://url/log/"+d.getFullYear()+"-"+(d.getMonth()+1)+"-"+(d.getDate())+"_localcontrol-story.log",%20"_self");
您能否告诉我对此的修改,以便我以 2 位数格式获取月份和日期,并在必要时添加前导零?
I have a bookmarklet I use to check daily log files. However the bookmarklet I use only delivers the month and day in single digits, however the log files use double digits.
For example my bookmarklet delivers:
http://url/log/2009-5-4_localcontrol-story.log,
while the log file actually lives at:
http://url/log/2009-05-04_localcontrol-story.log
Below is my current code:
javascript:d=new%20Date();window.open("http://url/log/"+d.getFullYear()+"-"+(d.getMonth()+1)+"-"+(d.getDate())+"_localcontrol-story.log",%20"_self");
Can you tell me an adaptation to this so I get my month and date in 2 digit format with the leading zero if necessary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点痛苦,但我所做的是做这样的事情:(
添加前导零,并且
slice(-2)
获取最后 2 个字符)it's kind of a pain, but what I've done is to do stuff like this:
(add a leading zero, and
slice(-2)
takes the last 2 characters)