Javascript 从API字符串angularjs更改UTC时间输出
我正在制作一个twitter机器人,它从api中读取日出和日落的时间,然后将结果发布到twitter上。我想为日出和日落的输出时间增加两个小时,以匹配我的本地时间 例如,我现在的输出是 “日落:晚上8:10:09 日出时间:凌晨1:01:19“ 我希望是这样 “日落:晚上10:10:09 日出时间:凌晨3:01:19“ 你有什么想法吗 angularJs代码: 控制器Javascript 从API字符串angularjs更改UTC时间输出,javascript,angularjs,utc,Javascript,Angularjs,Utc,我正在制作一个twitter机器人,它从api中读取日出和日落的时间,然后将结果发布到twitter上。我想为日出和日落的输出时间增加两个小时,以匹配我的本地时间 例如,我现在的输出是 “日落:晚上8:10:09 日出时间:凌晨1:01:19“ 我希望是这样 “日落:晚上10:10:09 日出时间:凌晨3:01:19“ 你有什么想法吗 angularJs代码: 控制器 $http.get("https://api.sunrise-sunset.org/json? lat=63.8258&
$http.get("https://api.sunrise-sunset.org/json?
lat=63.8258&lng=20.2630&date=today", {})
.then(function(response){
console.log("Sunrise: " + response.data.results.sunrise);
console.log("Sunset: " + response.data.results.sunset);
$scope.string = ("sunset: " + response.data.results.sunset + "\n" +
"sunrise: " + response.data.results.sunrise);
});
$scope.post_tweet = function(){
$http.post('index.php',{
'string':$scope.string
}).then(function(response){
//clear the form fields
$scope.msg = true;
$timeout(function(){$scope.msg = false;}, 1000);
console.log("in " + response.data);
});
我想应该是把时间格式化。您可以尝试获取未格式化的日期 例: 返回: {"results":{"sunrise":"2018-05-23T05:04:11+00:00","sunset":"2018-05-23T19:24:45+00:00","solar_noon":"2018-05-23T12:14:28+00:00","day_length":51634,"civil_twilight_begin":"2018-05-23T04:34:44+00:00","civil_twilight_end":"2018-05-23T19:54:13+00:00","nautical_twilight_begin":"2018-05-23T03:58:23+00:00","nautical_twilight_end":"2018-05-23T20:30:33+00:00","astronomical_twilight_begin":"2018-05-23T03:18:34+00:00","astronomical_twilight_end":"2018-05-23T21:10:22+00:00"},"status":"OK"} {“结果”:“日出”:“2018-05-23T05:04:11+00:00”,“日落”:“2018-05-23T19:24:45+00:00”,“太阳中午”:“2018-05-23T12:14:28+00:00”,“日长”:51634,“民用暮光之城开始”:“2018-05-23T04:34:44+00:00”,“民用暮光之城结束”:“2018-05-23T19:54:13+00:00”,“航海暮光之城开始”:“2018-05-23T03:58+00:00”:“航海暮“2018-05-23T20:30:33+00:00”,“天文曙光开始”:“2018-05-23T03:18:34+00:00”,“天文曙光结束”:“2018-05-23T21:10:22+00:00”},“状态”:“OK”} 然后在代码中,如果您尝试将JSON日期字符串转换为日期对象,即新日期(results.sunrise),则新日期返回的值将位于您的本地时区中 建议:我建议您可能希望使用日期转换/格式设置