有了这个URL,我想为创建一个bookmarklet,以便使用当前UTC日期/时间(年、月、日和(小时+6))的变量访问最新数据:
https://www.ogimet.com/cgi-bin/gsynres?ind=02464&lang=en&decoded=yes&ndays=2&ano=2021&mes=07&day=07&hora=18
有可能实现吗?
发布于 2021-07-08 01:00:51
一些JavaScript代码可以做到这一点。谢天谢地,如果值大于24,setHours()会更新日/月,依此类推。
let d = new Date();
d.setHours(d.getHours() + 6);
console.log(`https://www.ogimet.com/cgi-bin/gsynres?ind=02464&lang=en&decoded=yes&ndays=2&ano=${d.getFullYear()}&mes=${d.getMonth()}&day=${d.getDate()}&hora=${d.getHours() + 6}`);
使用bookmarkleter为我们提供了:
javascript:void%20function(){let%20a=new%20Date;a.setHours(a.getHours()+6),window.open(`https://www.ogimet.com/cgi-bin/gsynres%3Find=02464%26lang=en%26decoded=yes%26ndays=2%26ano=${a.getFullYear()}%26mes=${a.getMonth()}%26day=${a.getDate()}%26hora=${a.getHours()+6}`)}();
发布于 2021-07-10 06:43:05
使用window.open()
方法和getUTC
方法修改您的答案(@ScottJodoin)使其生效。网站在网址中接受了>24小时的值,这使得setHours()
变得不必要。
let d = new Date();
window.open(`https://www.ogimet.com/cgi-bin/gsynres?ind=02464&lang=en&decoded=yes&ndays=2&ano=${d.getUTCFullYear()}&mes=${d.getUTCMonth()+1}&day=${d.getUTCDate()}&hora=${d.getUTCHours()+6}`,'_self');
Bookmarkleter中的转换提供:
javascript:void%20function(){let%20a=new%20Date;window.open(`https://www.ogimet.com/cgi-bin/gsynres%3Find=02464%26lang=en%26decoded=yes%26ndays=2%26ano=${a.getUTCFullYear()}%26mes=${a.getUTCMonth()+1}%26day=${a.getUTCDate()}%26hora=${a.getUTCHours()+6}`,%22_self%22)}();
https://stackoverflow.com/questions/68289099
复制相似问题