Sunday, January 12, 2014

ASP.NET code to display Server Side Time along with client-side script to display Client Side Time.



ASP.NET code to display Server Side Time along with client-side script to display Client Side Time.

Source Code: -
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<%  Response.Write("<font color=blue size=5>Server Side Information</font><br> Current Date is: - " & Today() & "<br>  Current time is: - " & TimeOfDay() & "<br> Month Name is : -" & MonthName(Month(Today())) & "<br>Weekday Name is: - " & WeekdayName(Weekday(Today)) & "<br>  <font color=blue size= 5><b>Client Side Information: -</b></font><br>")%>
<script language=javascript>
var d = new Date()
var time = d.getHours()
var mn=d.getMonth()
var monthNames = [ "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December" ];
var dayNames = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
    "Saturday" ];
var objDate = new Date(),
    locale = "en_us",
    month = objDate.toLocaleString(locale, { month: "long" });
var currentDate = new Date()
      var day = currentDate.getDate()
      var month = currentDate.getMonth() + 1
      var year = currentDate.getFullYear()

document.write("<b>Current date is: -" + day + "/" + month + "/" + year + "</b>")
var currentTime=new Date()
    var hr = currentTime.getHours()
    var min= currentTime.getMinutes()
    var sec=currentTime.getSeconds()
document.write ("<br>Current Time is: -" + hr + ":" + min + ":" + sec);
document.write("<br>The current month is:-  " + monthNames[d.getMonth()]);
document.write("<br>The current weekday is:-  " + dayNames[d.getDay()]);
</script>
    <form id="form1" runat="server">    <div>        </div>    </form></body></html>

1 comment:

  1. What about output....
    Can you give me the output please....

    ReplyDelete