Time Machine for Weather
Get the last 10 days of weather history data.
Let’s say, today is December 30, you can get historical data from Dec. 20 to Dec. 29.
QWeather also provides historical reanalysis weather data from 2000 to present. If you need more historical weather data, please provide the following information to sales@qweather.com.
- Company name
- Contact information
- City or coordinates
- Date range
| Interface code | Interface | Class |
|---|---|---|
| historicalWeather | Historical weather | HistoricalWeatherResponse |
Parameters
HistoricalWeatherParameter
-
location(required)The location to be queried, only support LocationID and LocationID can be obtained by GeoAPI. For example:location=101010100 -
date(required)Set the date, up to the most recent 10 days. The date format is yyyyMMdd. Example:date=20200531 -
langMulti-language setting, please see Language to find out how our multi-language works and how to set up. -
unitSet weather data unit, the available value areunit=mfor metric(default) andunit=ifor imperial. See more about Unit.
Sample code
Swift
Task{
do {
let threeDaysAgo = Calendar.current.date(byAdding: .day, value: -3, to: Date())!
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMdd"
let date = formatter.string(from: threeDaysAgo)
let parameter = HistoricalWeatherParameter(location: "101010100", date: date)
let response = try await QWeather.instance
.historicalWeather(parameter)
print(response)
} catch QWeatherError.errorResponse(let error) {
print(error)
} catch {
print(error)
}
}
Objective-C
NSDate * threeDaysAgo = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay value:-3 toDate:[NSDate date] options:0];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString * date = [formatter stringFromDate:threeDaysAgo];
HistoricalWeatherParameter *parameter = [HistoricalWeatherParameter instanceWithLocation:@"101010100" date:date lang:@(LangZH_HANS) unit:@(UnitMETRIC)];
[QWeatherObjc historicalWeather:parameter completionHandler:^(HistoricalWeatherResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
NSLog(@"%@", response.description);
}
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}];
Response
HistoricalWeatherResponse
-
codeSee Status Code -
fxLinkResponsive web page of this data, for embedded in website or APP -
weatherDaily.dateDate -
weatherDaily.sunriseSunrise time. Maybe null in high latitude area -
weatherDaily.sunsetSunset time. Maybe null in high latitude area -
weatherDaily.moonriseMoonrise time of current day. Maybe null -
weatherDaily.moonsetMoonset time of current day. Maybe null -
weatherDaily.moonPhaseMoon phase name -
weatherDaily.tempMaxThe highest temperature of the day -
weatherDaily.tempMinThe lowest temperature of the day -
weatherDaily.precipEstimated total precipitation for the day -
weatherDaily.pressureAtmospheric pressure, hPa -
weatherDaily.humidityDaily relative humidity in percent -
weatherHourly.timeTime of the day -
weatherHourly.tempHourly temperature -
weatherHourly.iconIcon code for hourly weather conditions of the day. See also QWeather Icons -
weatherHourly.textHourly weather condition -
weatherHourly.wind360Hourly wind direction in azimuth degree -
weatherHourly.windDirHourly wind direction -
weatherHourly.windScaleHourly wind scale -
weatherHourly.windSpeedHourly wind speed, KM/H -
weatherHourly.humidityHourly relative humidity in percent -
weatherHourly.precipHourly accumulated precipitation -
weatherHourly.pressureAtmospheric pressure, hPa -
refer.sourcesData source and other statements, may be null -
refer.licenseData license, may be null