Search code examples
javascriptbookmarks

How do I create a bookmark that inputs current date and time (considering timezone)?


In my company I often deal with coworkers and customers across multiple timezones. I currently use the website https://www.timeanddate.com to look at the timezone. However, when i save the URL as a bookmark it is only for the given date that it was saved. I would like the date to dynamically pull for the current date and time. I'd also like to share this with my coworkers in Europe so that they can also take advantage of this.

the url is broken down like this:

https://www.timeanddate.com/worldclock/converter.html?iso=[yyyy][MM][DD]T[UTChh][mm][ss]&p1=1440&p2=240&p3=102&p4=204&p5=136&p6=25&p7=155.

The &'s at the end are all the timezones that I would like converted. I have done some research and discovered that it looks like Chrome supports javascript in the book mark URL.


Solution

  • Here I've taken the answer you came up with yourself and fixed some issues with it:

    javascript:function url() { 
      function padd(val) {
        return ('0' + val).slice(-2);
      }
      var date = new Date(); 
      var y = date.getUTCFullYear(); 
      var m = padd(date.getUTCMonth() +1);
      var d = padd(date.getUTCDate()); 
      var h = padd(date.getUTCHours()); 
      var n = padd(date.getUTCMinutes());
      var s = padd(date.getUTCSeconds()); 
      var dateString = y + '-' + m + '-' + d + 'T' + h + ':' + n + ':' + s; 
      return 'https://www.timeanddate.com/worldclock/converter.html?iso=' + dateString + '&p1=1440&p2=240&p3=102&p4=204&p5=136&p6=25&p7=155' } window.open(url(),"_blank");