0
message.channel.send(`

            \nThe Current Weather
            \nLocation: ${parsedWeather.name}, ${parsedWeather.sys.country}
            \nForecast: ${parsedWeather.weather[0].main}
            \nCurrent Temperature: ${(Math.round(((parsedWeather.main.temp - 273.15) * 9 / 5 + 32)))}° F
            \nHigh Temperature: ${(Math.round(((parsedWeather.main.temp_max - 273.15) * 9 / 5 + 32)))}° F
            \nLow Temperature: ${(Math.round(((parsedWeather.main.temp_min - 273.15) * 9 / 5 + 32)))}° F
            \nSun Rise: ${new Date((parsedWeather.sys.sunrise).toLocaleDateString("en-US"))}
            \nSun Set: ${new Date((parsedWeather.sys.sunset).toLocaleDateString("en-US"))}
            \nTime: ${new Date((parsedWeather.timezone).toLocaleDateString("en-US"))}

            `);

I'm not sure how to properly type out my function so I do not receive an error the "parsedWeather.timezone" gives me a unix timestamp and I need it converted but this does not seem to be working I need it converted to MM/DD/YY Time, Time Zone

Forge Mods
  • 25
  • 1
  • 9
  • Does this answer your question? [Convert UTC Epoch to local date](https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date) – Syntle May 07 '20 at 23:56
  • Not sure how to implement this into my code I've tried that but I still get errors – Forge Mods May 07 '20 at 23:59

1 Answers1

1

You've got your ()'s wrong. Instead of:

new Date((parsedWeather.sys.sunrise).toLocaleDateString("en-US"))

...do:

new Date(parsedWeather.sys.sunrise).toLocaleDateString("en-US")

In the first case you're taking a string expression parsedWeather.sys.sunrise and trying to call a non-existent toLocaleDateString method on that. In the second case, you're calling the method on a Date expression.

Jacob
  • 77,566
  • 24
  • 149
  • 228
  • Kind of what I was looking for but it is displayed as "1/19/1970" with no time, but that's the wrong date so I'm I taking the wrong approach for this? 1588846632 <--- is the sunrise 1588898284 <--- is the sunset -14400 <---- is the timezone – Forge Mods May 08 '20 at 00:10
  • Do you want to use `toLocaleString` instead, then? There are lots of string formatting methods here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date. Or if those standard ones don't work, you could try using https://momentjs.com/ – Jacob May 08 '20 at 00:13
  • Note that `toLocaleString` and the like also let you specify the timezone you want the date represented in. – Jacob May 08 '20 at 00:16
  • Well I tried it and it said "Monday, January 19, 1970 4:20 AM" I'm trying to convert it to today's time – Forge Mods May 08 '20 at 00:25
  • Looks like your timestamps are _seconds since Unix Epoch_, whereas JavaScript timestamps are in _milliseconds_. If you multiply by 1000 you'll have a better time. – Jacob May 08 '20 at 01:04