Sunrise and Sunset
Get the sunrise and sunset times for any location around the world for the next 60 days.
Interface code | Interface | Class |
---|---|---|
astronomySun | Sunrise and sunset data | AstronomySunResponse |
Parameters
AstronomySunParameter
-
location
(required)The location to be queried, support LocationID or comma-separated longitude and latitude (decimal, up to 2 decimal places), LocationID can be obtained by GeoAPI. Example:location=101010100
orlocation=116.41,39.92
-
date
(required)Set the date, up to 60 days in the future (including today). The date format is yyyyMMdd. Example:date=20200531
Sample code
Swift
Task {
do {
let formatter = DateFormatter()
formatter.dateFormat = "yyyMMdd"
let date = formatter.string(from: Date())
let parameter = AstronomySunParameter(location: "101010100", date: date)
let response = try await QWeather.instance
.astronomySun(parameter)
print(response)
} catch QWeatherError.errorResponse(let error) {
print(error)
} catch {
print(error)
}
}
Objective-C
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString * date = [formatter stringFromDate:[NSDate date]];
AstronomySunParameter *parameter = [AstronomySunParameter instanceWithLocation:@"101010100" date:date];
[QWeatherObjc astronomySun:parameter completionHandler:^(AstronomySunResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
NSLog(@"%@", response.description);
}
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}];
Response
AstronomySunResponse
-
code
See Status Code -
updateTime
API last update time -
fxLink
Responsive web page of this data, for embedded in website or APP -
sunrise
Sunrise time. Maybe null in high latitude area -
sunset
Sunset time. Maybe null in high latitude area -
refer.sources
Data source and other statements, may be null -
refer.license
Data license, may be null