Introduction:
Here I will explain how to get current datetime in jquery or JavaScript.
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.
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.
<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. |
|||
|
|||
5 comments :
How get system datetime in asp.net (C#) not hosting server datetime
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);
@Ganapathi..
Thanks i updated the post.
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
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
Note: Only a member of this blog may post a comment.