How to format date by jQuery date object with examples

jQuery date

In this tutorial, we will show you how to format date and use it in HTML document with jQuery. There are date plug-ins as well that you can include in your document and format as per requirement.

See jQuery date format example online

In the following example, we will create a jQuery date object and show you how to format and present it into an element.

Example of current date format in MM/DD/YYYY with jQuery

The example below creates a date object and then formats the date into MM/DD/YYYY. As you click on the button, the div element will be filled with current date by using jQuery append method.

jQuery date format

Experience this example online

Example of current time example with jQuery

The example below will show current time as you click on the button.

jQuery date format time

Experience this example online

You can see in the code, the date object is created and the current time is assigned to a variable by using the getHours, getMinutes, and getSeconds properties of the date object.

The plugins can be found here:


Useful reading: jQuery append