edit unix time

This commit is contained in:
madarsbiss 2021-07-20 21:58:08 +03:00
parent 859bfadc9f
commit 7d8f418eae

View File

@ -47,6 +47,20 @@ export default function Home() {
return arr[val % 16]; return arr[val % 16];
} }
const convertTime = (unixSeconds, timezone) => {
const time = new Date((unixSeconds + timezone) * 1000)
.toISOString()
.match(/(\d{2}:\d{2})/);
return time;
};
// console.log(
// new Date(weatherData.dt * 1000).toISOString().match(/(\d{2}:\d{2}:\d{2})/)
// );
console.log(convertTime(weatherData.dt, weatherData.timezone));
return ( return (
<div className={styles.wrapper}> <div className={styles.wrapper}>
{weatherData && ( {weatherData && (
@ -113,7 +127,7 @@ export default function Home() {
/> />
<div> <div>
<h1>{weatherData.wind.speed}</h1> <h1>{weatherData.wind.speed}</h1>
<p>Km/h</p> <p>m/s</p>
</div> </div>
</div> </div>
</div> </div>
@ -142,7 +156,7 @@ export default function Home() {
/> />
<div> <div>
<h1>{weatherData.visibility / 1000}</h1> <h1>{weatherData.visibility / 1000}</h1>
<p>Km</p> <p>km</p>
</div> </div>
</div> </div>
</div> </div>
@ -175,12 +189,12 @@ export default function Home() {
/> />
<div> <div>
<h1> <h1>
{" "} {
{new Date(weatherData.sys.sunrise * 1000).getHours()}: convertTime(
{(new Date(weatherData.sys.sunrise * 1000).getMinutes() < 10 weatherData.sys.sunrise,
? "0" weatherData.timezone
: "") + )[0]
new Date(weatherData.sys.sunrise * 1000).getMinutes()} }
</h1> </h1>
<p>AM</p> <p>AM</p>
</div> </div>
@ -210,11 +224,12 @@ export default function Home() {
/> />
<div> <div>
<h1> <h1>
{new Date(weatherData.sys.sunset * 1000).getHours()}: {
{(new Date(weatherData.sys.sunset * 1000).getMinutes() < 10 convertTime(
? "0" weatherData.sys.sunset,
: "") + weatherData.timezone
new Date(weatherData.sys.sunset * 1000).getMinutes()} )[0]
}
</h1> </h1>
<p>PM</p> <p>PM</p>
</div> </div>