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

Try date object methods #31

Open
oliverjam opened this issue Feb 11, 2022 · 0 comments
Open

Try date object methods #31

oliverjam opened this issue Feb 11, 2022 · 0 comments

Comments

@oliverjam
Copy link

oliverjam commented Feb 11, 2022

const currDate = date.toString().slice(4, 11).trim();
const day = Number(currDate.toString().slice(5, 7).trim());
const month = currDate.slice(0, 3);

I'd recommend not relying on string parsing for dates. It'll always get weird cause dates have so many edge-cases.

Luckily JS date objects have built-in methods for this stuff. E.g.

let date = new Date(); // 2022-02-11T10:14:04.717Z
date.getDate(); // 11
date.getMonth() + 1; // 2 (months are 0-indexed lol)
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