Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect month in formatted timestamp #13

Open
SorinTheSleuth opened this issue Mar 27, 2024 · 0 comments
Open

Incorrect month in formatted timestamp #13

SorinTheSleuth opened this issue Mar 27, 2024 · 0 comments

Comments

@SorinTheSleuth
Copy link

The getUTCMonth function in JavaScript returns the month of the date as an integer value from 0 (January) to 11 (December), so it needs to be adjusted to get a human-readable month (1-12). The code is converting the return value of getUTCMonth to a string and padding it, but it does not account for the fact that getUTCMonth is zero-based. As a result, the formatted date string would show January as 00 instead of 01, and December as 11 instead of 12. To fix this, the value returned from getUTCMonth should be incremented by 1 before converting to a string and padding.

const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');

This adjustment would ensure that the month is displayed correctly in the timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant