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

get date string of today #2

Open
cybeaer opened this issue Oct 8, 2020 · 1 comment
Open

get date string of today #2

cybeaer opened this issue Oct 8, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@cybeaer
Copy link
Owner

cybeaer commented Oct 8, 2020

YYYYMMDD of today

@cybeaer cybeaer added the enhancement New feature or request label Oct 8, 2020
@cybeaer cybeaer self-assigned this Oct 8, 2020
@qusaifares
Copy link

MomentJS is a very popular JavaScript library used to get formatted date strings. Might be your best friend.

However, if you're looking to do it with plain JavaScript, this method should work:

const today = new Date();

const mm = today.getMonth() + 1; // getMonth() is zero-based
const dd = today.getDate();

const todayFormatted = [today.getFullYear(),
        (mm>9 ? '' : '0') + mm,
        (dd>9 ? '' : '0') + dd
       ].join('');
// date in YYYYMMDD

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

No branches or pull requests

2 participants