This Blog is for show current date and time with out post back.
Code for .aspx page in body section
- <label id="Date"></label> | <label id="hours"></label><span style="text-decoration:blink">:</span><label id="min"></label><label id="point1" style="text-decoration:blink">:</label><label id="sec"></label> <label id="ampm"></label>[Login Time:<asp:Label ID="lbl_time" runat="server" Text=""></asp:Label>
Java script fuction for show date and time
- $(document).ready(function () {
-
- var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
- var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
-
-
- var newDate = new Date();
-
- newDate.setDate(newDate.getDate());
-
- $('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
-
- setInterval(function () {
-
- var seconds = new Date().getSeconds();
-
- $("#sec").html((seconds < 10 ? "0" : "") + seconds);
- }, 1000);
-
- setInterval(function () {
-
- var minutes = new Date().getMinutes();
-
- $("#min").html((minutes < 10 ? "0" : "") + minutes);
- }, 1000);
-
- setInterval(function () {
-
- var hours = new Date().getHours() == 0 ? "12" : new Date().getHours() > 12 ? new Date().getHours() - 12 : new Date().getHours();
-
-
- $("#hours").html((hours < 10 ? "0" : "") + hours);
- }, 1000);
- setInterval(function () {
- var ampm = new Date().getHours() < 12 ? "AM" : "PM";
- $("#ampm").html(ampm);
- }, 1000);
- });
Save above java script name as ClockPlugin.js
Than call it on head section...
- <script src="ClockPlugin.js" type="text/javascript"></script>
Now run this u can see date and time like a timer.
Enjoy.