I am working with a CurrentWeather Model retrieved from localStorage and parsed into an object.
export interface CurrentWeather {
LocalObservationDateTime: Date;
Latitude: string;
Longitude: string;
LocationKey: string;
LocalizedName: string;
PrimaryPostalCode: string;
Temperature: number;
RealFeelTemperature: number;
WeatherText: string;
UvIndex: number;
UvIndexText: string;
}
const currentWeatherData: CurrentWeather = JSON.parse(localStorage.getItem('currentWeather'));
After parsing the data, I need to extract the hours from the LocalObservationDateTime. However, I encountered an error stating "Cannot read property 'getHours' of undefined".
var localHour = currentWeatherData.LocalObservationDateTime.getHours();
I tried using new Date() on the Date object as suggested somewhere but it did not work.
const localDate: Date = new Date(currentWeatherData.LocalObservationDateTime);
const localDateHour = localDate.getHours();