Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to get current datetime in jquery/JavaScript

Aug 20, 2012
Introduction

Here I will explain how to get current datetime in jquery or JavaScript.

Description:
  
In previous articles I explained auto refresh page ,
expand textbox on focus and disable right click on image using JQuery and many articles relating to JQuery. Now I will explain how to get current datetime in JQuery or JavaScript in asp.net.

Get current datetime in jquery

Please check below code to get current datetime using jquery


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Current Datetime in JQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
var param1 = new Date();
var param2 = param1.getDate() + '/' + (param1.getMonth()+1) + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
$('#lbltxt').text(param2)
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lbltxt"/>
</div>
</form>
</body>
</html>
Get Current Datetime in JavaScript

Check below code to get current datetime in JavaScript


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Current Datetime in JQuery</title>
<script type="text/javascript" language="javascript">
function GetDateTime()
{
var param1 = new Date();
var param2 = param1.getDate() + '/' + (param1.getMonth()+1) + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
document.getElementById('lbltxt').innerHTML = param2;
}
</script>
</head>
<body onload="GetDateTime()">
<form id="form1" runat="server">
<div>
<label id="lbltxt"/>
</div>
</form>
</body>
</html>
Demo



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

5 comments :

Hitesh Jariwala said...

How get system datetime in asp.net (C#) not hosting server datetime

Ganapathi said...

Hi , i like this site, its very useful
In JavaScript Date object the months counter starts from 0, so we have to correct this. param1.setMonth(param1.getMonth() + 1);

Suresh Dasari said...

@Ganapathi..
Thanks i updated the post.

LIFE said...

hi i have used the code of current datetime but when i m using the code only the date and time is dispalyed but my whole code output is not displaying

LIFE said...

hi i have used the code of current datetime but when i m using the code only the date and time is dispalyed but my whole code output is not displaying

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.