现在的位置: 首页 > 综合 > 正文

ASP.NET页面显示日期

2013年10月01日 ⁄ 综合 ⁄ 共 596字 ⁄ 字号 评论关闭

    在asp.net制作的web页面中显示日期时 ,可以显示服务器的日期也可以显示当前客户端的日期。具体操作的办法是:

显示服务器的日期可以直接使用asp.net自带的日期函数,DateTime.Now.Tostring("G");

G就是格式化字符串

客户端日期的显示要通过javascript脚本来实现,在需要的地方

输入脚本:

            <script language="JavaScript">
   <!--
   document.ns = navigator.appName == "Netscape"
   tmpDate = new Date();
   date = tmpDate.getDate();
   month= tmpDate.getMonth() + 1 ;
   if(document.ns)
   {
    year1=tmpDate.getYear()
    year= year1.toString().substr(1,2);
   }
   else
    year= tmpDate.getYear();
   
   document.write(year);
   document.write(".");
   document.write(month);
   document.write(".");
   document.write(date);
   // -->
    </script>

抱歉!评论已关闭.