How to get current Date and Time using JavaScript

In this tutorial i will let you know the very esay and simple way to get current Date and Time using JavaScript code. I will explain with demo examples because i know examples are 1000 time better than text explanations. It is often easier to understand the code.

You can get the current date and time using var today = new Date(); function, It will return the standard date time format like below if you are from india:

JavaScript get current date

1

2

3

4

5

6

7

<pid="example1"></p>

<script type="text/javascript">

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

</script>

Output:

1

2

3

Tue Jan31201716:39:00GMT+0530(India Standard Time)

Use below code to get current date from JavaScript Date() object in Y-m-d format.

JavaScript ISO (Date-Time) format

1

2

3

vardatetime=newDate("2015-03-25T12:00:00Z");

Output:

1

2

3

Wed Mar25201514:26:24GMT+0530(India Standard Time)

About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.
View all posts by Prem Tiwari