views:

292

answers:

1

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?

+5  A: 

it's kind of a pain, but what I've done is to do stuff like this:

("0"+d.getDate()).slice(-2)

(add a leading zero, and slice(-2) takes the last 2 characters)

Jason S