简体   繁体   English

如何创建输入当前日期和时间(考虑时区)的书签?

[英]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. 我目前使用网站https://www.timeanddate.com查看时区。 However, when i save the URL as a bookmark it is only for the given date that it was saved. 但是,当我将URL保存为书签时,它仅在给定的日期被保存。 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 . 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. 我进行了一些研究,发现Chrome似乎在书签URL中支持javascript。

I found the answer 我找到了答案

function url() {
  var date = new Date(); 
  var o = date.getTimezoneOffset()/60; 
  var y = date.getFullYear(); 
  var m = date.getMonth() +1;
  if(m < 10){
    m = '0' + m;
  } 
  var d = date.getDate(); 
  if(d < 10){
    d = '0' + d;
  } 
  var h = date.getHours()+o;
  if(h < 10){
    h = '0' + h;
  }
  var n = date.getMinutes(); 
  if(n < 10){
    n = '0' + n;
  } 
  var date = y + m + d + 'T' + h + n;
  return 'https://www.timeanddate.com/worldclock/converter.html?iso=' + date + '00&p1=1440&p2=240&p3=102&p4=204&p5=136&p6=25&p7=155' 
} 
window.open(url(),"_blank");

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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 JavaScript 的页面上显示当前时区、日期和时间? - How can I show the current timezone, date, and time on the page in JavaScript? AngularJS,如何将多个输入组合到单个ng模型中? 具体来说,要将日期,时间和时区输入组合到datetime对象中 - AngularJS, how do I combine multiple inputs into a single ng-model? Specifically, to combine a date, time, and timezone input into a datetime object 如何在其他时区保存日期/时间 - How do I save date/time in some other timezone 如何显示当地时间(考虑时区)? - How to display local time (considering timezone)? 如何考虑时区Node.js / JavaScript来创建JS日期对象 - How create a JS date object considering timezone Node.js / javascript 如何在 sequelize 中使用数据库时区获取当前日期/时间 - How to get current date/time using database timezone in sequelize 如何才能显示当前DATE但在所选时区内? - How do I get this to display only the current DATE but within the selected timezone? 如何指定时区,以便时刻可以给出该时区的正确日期? - How do I specify timezone such that moment will give proper date for that timezone? 如何在Chrome浏览器中创建书签,该书签会弹出一个添加URL的弹出窗口? - How do I create a bookmark in chrome that gives a popup to append a URL? 如何以特定格式显示当前日期和时间? - How do I display the current date and time in a specific format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM