Time Zone: Nodejs

I’ve faced a lot of obstacles while developing web apps, but I’ve never had to deal with time zone issues.
I decided to write this brief post to help anyone who might find themselves in the same situation.
The solution was discovered thanks to the help…


This content originally appeared on DEV Community and was authored by Abayomi Ogunnusi

I've faced a lot of obstacles while developing web apps, but I've never had to deal with time zone issues.
I decided to write this brief post to help anyone who might find themselves in the same situation.
The solution was discovered thanks to the help of a colleague.

timezone

After writing the logic for a service apartment booking app check site here, I discovered that the email was not sending the correct time in the booking receipt. I live in Africa, Nigeria to be precise yet the time zone supplied to the user after a successful booking was eastern standard time i.e the previous day to my current time. In my case:
Fri Dec 17 2021 to Sat Dec 18 2021 instead of Sat Dec 18 2021 to Sun Dec 19 2021
Image description

✅ The quick fix was:

const express = require('express');
const app = express();
const port = process.env.PORT || 4545

process.env.TZ ="Africa/Lagos"

...

app.listen(port, () => {
    console.log(`Server Established and  running on Port ⚡${port}`)
})

Conclusion

You can easily set your time zone to a correct value by using process.env.TZ ="Continent/Country". I hope this post was helpful. Thanks for reading.


This content originally appeared on DEV Community and was authored by Abayomi Ogunnusi


Print Share Comment Cite Upload Translate Updates
APA

Abayomi Ogunnusi | Sciencx (2021-12-01T23:36:40+00:00) Time Zone: Nodejs. Retrieved from https://www.scien.cx/2021/12/01/time-zone-nodejs/

MLA
" » Time Zone: Nodejs." Abayomi Ogunnusi | Sciencx - Wednesday December 1, 2021, https://www.scien.cx/2021/12/01/time-zone-nodejs/
HARVARD
Abayomi Ogunnusi | Sciencx Wednesday December 1, 2021 » Time Zone: Nodejs., viewed ,<https://www.scien.cx/2021/12/01/time-zone-nodejs/>
VANCOUVER
Abayomi Ogunnusi | Sciencx - » Time Zone: Nodejs. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/01/time-zone-nodejs/
CHICAGO
" » Time Zone: Nodejs." Abayomi Ogunnusi | Sciencx - Accessed . https://www.scien.cx/2021/12/01/time-zone-nodejs/
IEEE
" » Time Zone: Nodejs." Abayomi Ogunnusi | Sciencx [Online]. Available: https://www.scien.cx/2021/12/01/time-zone-nodejs/. [Accessed: ]
rf:citation
» Time Zone: Nodejs | Abayomi Ogunnusi | Sciencx | https://www.scien.cx/2021/12/01/time-zone-nodejs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.