Languages
[Edit]
EN

JavaScript - custom date & time format

6 points
Created by:
Reilly-Collier
860

In this article, we would like to show you how to use the custom format date and time in JavaScript.

yyyy.MM.dd_HH.mm.ss format for DateTime - JavaScript
yyyy.MM.dd_HH.mm.ss format for DateTime - JavaScript

 

To do this, we will use the padStart function, which pads the given string with another string until it is the desired length.

Check out the example below to see how it works:

Note: 

The padStart function is a relatively new feature (ES2017) and may not be compatible with all browsers, it is worth to protect against it and add a polyfill to our web page or paste just following code:

References

Edit
  1. padStart - MDN Docs
  2. JavaScript - how to get only current date?

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Date & Time

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join