[英]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.