JS实现显示当前日期的实例代码
程序员文章站
2022-05-20 22:46:33
写在前面:
在做项目中,经常会用到显示当前日期这个功能,在此,记录下来,方便日后查阅。
先给大家展示下效果图:
由于功能较简单,这里就直接将代码搬上来吧...
写在前面:
在做项目中,经常会用到显示当前日期这个功能,在此,记录下来,方便日后查阅。
先给大家展示下效果图:
由于功能较简单,这里就直接将代码搬上来吧
<%-- created by intellij idea. user: administrator date: 2018/6/12 time: 8:17 --%> <%@ page contenttype="text/html;charset=utf-8" language="java" %> <% string scheme = request.getscheme(); string servername = request.getservername(); string contextpath = request.getcontextpath(); int port = request.getserverport(); //网站的访问跟路径 string baseurl = scheme + "://" + servername + ":" + port + contextpath; request.setattribute("baseurl", baseurl); system.out.println("baseurl:" + baseurl); %> <html> <head> <title>js实现当前日期显示</title> <script src="${baseurl}/bootstrap/bootstrap/assets/js/jquery-1.10.2.min.js"></script> </head> <body style="text-align: center"> <div> <span id="mytime" style="font-size: 18px;color: #00be67"></span> </div> </body> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ var date = new date(); var weekday = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; var year = date.getfullyear(); var month = date.getmonth()+1; var day = date.getdate(); var week = weekday[date.getday()]; //alert(year+","+month+","+day+","+week) $("#mytime").html(year+"年"+month+"月"+day+"日      "+week); } ); </script> </html>
总结
以上所述是小编给大家介绍的js实现显示当前日期的实例代码,希望对大家有所帮助