How to get current Date and Time using JavaScript

How to get current Date and Time using JavaScript

Today, We want to share with you How to get current Date and Time using JavaScript.
In this post we will show you JavaScript Date and Time, hear for JavaScript get current date yyyy-mm-dd we will give you demo and example for implement.In this post, we will learn about Examples – Getting current date and time in JavaScript with an example.

JavaScript current date Syntax

var js_dt = new Date();

var js_dt = new Date(milliseconds);

var js_dt = new Date('date string');

var js_dt = new Date(year, month[, date, hour, minute, second, millisecond]);

JavaScript get current date Example

<!DOCTYPE html>
<html>
<body>
	<h1>Demo: Current Date</h1>
	<p id="print_date"></p>
	<p id="live_date"></p>
	
	<script>

		document.getElementById("print_date").innerHTML = Date();

		var live_date = new Date();

		document.getElementById("live_date").innerHTML = live_date;

    </script>
</body>
</html>

JavaScript Date Formats

There are the Following the List of the JavaScript Date Formats

  • getDate()
  • getDay()
  • getFullYear()
  • getHours()
  • getMilliseconds()
  • getMinutes()
  • getMonth()
  • getSeconds()
  • getTime()
Read Also:  How to upload image in codeigniter mysql database and display?

Date Separators of the components:

  • ” ” – spaces
  • “/” – stroke (slash)
  • “-” – hyphens or dashes
  • “.” – dots or full stops/points (periods)

Specific formats for the Basic components of a calendar date

  • d – day of the month for days below 10, e.g. 2
  • dd – day of the month, e.g. 02
  • ddd – abbreviation for day of the week, e.g. Tue
  • dddd – day of the week spelled out in full, e.g. Tuesday
  • m – month for months below 10, e.g. 4
  • mm – month, e.g. 04
  • mmm – abbreviation for month, e.g. Apr
  • mmmm – month spelled out in full, e.g. April
  • yy – year, e.g. 96
  • yyyy – year, e.g. 1996
Read Also:  Radio button Component in VueJS

Date Formats

  • yyyymmdd 20190803
  • yyyy/mm/dd 2019/08/03
  • yyyy-mm-dd time24 (ODBC Std) 2019-08-03 18:55:30
  • yyyy-mm-dd 2019-08-03
  • yyyy 2019
  • yymmdd 190803
  • yy/mm/dd 19/08/03
  • yy 19
  • weekday, dth mmmm yyyy Monday, 3 of August 2019
  • weekday Monday
  • time24 18:55:30
  • time12 6:55:30 pm
  • seconds 68538.350
  • mmm-yy Aug-19
  • mmm-dd-yyyy Aug-03-2019
  • mmm-dd-yy Aug-03-19
  • mmddyyyy 08032019
  • mmddyy 080319
  • mm/dd/yyyy 08/03/2019
  • mm/dd/yy 08/03/19
  • hours 48:55:30
  • dmmmyyyy 3Aug2019
  • dmmmyy 3Aug19
  • ddmmyyyy 03082019
  • ddmmyy 030819
  • ddmmmyyyy 03Aug2019
  • ddmmmyy 03Aug19
  • dd/mm/yyyy 03/08/2019
  • dd/mm/yy 03/08/19
  • dd-mmm-yyyy time12 03-Aug-2019 6:55:30 pm
  • dd-mmm-yyyy time 03-Aug-2019 18:55:30.35
  • dd-mmm-yyyy 03-Aug-2019
  • dd-mmm-yy 03-Aug-19
  • d/m/yyyy 3/8/2019
  • d/m/yy 3/8/19
  • d-mmmm-yyyy 3-August-2019
  • d-mmmm-yy 3-August-19
  • d-mmm-yyyy 3-Aug-2019
  • d-mmm-yy 3-Aug-19

Read :

Read Also:  vue Check box binding Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about JavaScript get current date Examples.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP MySQL CRUD Create, Insert, Update and Delete operations
  2. Read Also:  javascript String to Get Hours and Minutes
  3. Read Also:  registration and signin form in php and mysql with validation
  4. Read Also:  Display Live Date Time using JQuery and JavaScript
  5. Read Also:  How to Open URL in New Tab using Laravel
  6. Read Also:  How to Get Current Date & Time in JavaScript
  7. Read Also:  String Expressions using Angular Example
  8. Read Also:  How to display current date and time in html using javascript?
  9. Read Also:  How to resolve the "javascript runtime error function is undefined"?
  10. Read Also:  How to get current Date and Time using JavaScript?