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

Native Date format using toLocaleDateString #60

Open
jecovier opened this issue Nov 20, 2018 · 5 comments
Open

Native Date format using toLocaleDateString #60

jecovier opened this issue Nov 20, 2018 · 5 comments

Comments

@jecovier
Copy link

Hi, I really like this! thanks for your effort!

I Know it's not exactly the same, but i think you can add toLocaleDateString as an native option for date formatting. More in the link below:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

@stevemao
Copy link
Member

PR welcome

@Amorymeltzer
Copy link
Contributor

Well, for the examples in the table, I think all you need is:

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' };
date.toLocaleDateString('en-US', options);

and

var options = { weekday: 'short', hour: 'numeric'};
date.toLocaleDateString('en-US', options);

You can also put undefined as the first parameter if you want to be locale-neutral; would probably be worth a comment

@Amorymeltzer
Copy link
Contributor

I can make the simple PR, but tests fail because there's a comma difference:
Sunday, September 9, 2018 in native
Sunday, September 9th 2018 in moment

Native also doesn't support nth

@stevemao
Copy link
Member

@Amorymeltzer feel free to fix the test too.

Amorymeltzer added a commit to Amorymeltzer/You-Dont-Need-Momentjs that referenced this issue Oct 28, 2019
@aesyondu
Copy link

aesyondu commented Feb 9, 2020

How about Intl.DateTimeFormat? Performance note as mentioned in the toLocaleDateString mdn page.

Amorymeltzer added a commit to Amorymeltzer/You-Dont-Need-Momentjs that referenced this issue Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants