gpt4 book ai didi

javascript - 雅虎天气 API 返回缺少数字的日落/日出时间

转载 作者:行者123 更新时间:2023-12-03 04:47:47 27 4
gpt4 key购买 nike

如果分钟以 0 开头,它会删除数字 - 请参阅

https://query.yahooapis.com/v1/public/yql?q=select%20astronomy%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22los+angeles%2C%20ca%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

返回:

{"query":{"count":1,"created":"2017-03-14T23:40:02Z","lang":"en-us","results":{"channel":{"astronomy":{"sunrise":"7:5 am","sunset":"7:0 pm"}}}}}

同时

https://query.yahooapis.com/v1/public/yql?q=select%20astronomy%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22maui%2C%20hi%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

返回

{"query":{"count":1,"created":"2017-03-14T23:41:16Z","lang":"en-us","results":{"channel":{"astronomy":{"sunrise":"6:35 am","sunset":"6:35 pm"}}}}}

有解决这个问题的想法吗?我想我可以在冒号处对时间进行切片,然后将结果填充到 2 位数字,但这看起来很困惑。

最佳答案

var el = {"query":{"count":1,"created":"2017-03-14T23:49:12Z","lang":"ru-RU","results":{"channel":{"astronomy":{"sunrise":"7:5 am","sunset":"7:0 pm"}}}}};
var a = el.query.results.channel.astronomy;

for(var i in a)
{
if (/^\d{1,2}\:\d{1}\s/.test( a[i] ))
{
var value = /^\d{1,2}(\:\d)\s/.exec(a[i])[1];
a[i] = a[i].replace( value, ':0' + value.substr(1) )
}
}

console.log(a)

关于javascript - 雅虎天气 API 返回缺少数字的日落/日出时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42798592/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com