Posted in Javascript onJuly 03, 2018
写在前面:
在做项目中,经常会用到显示当前日期这个功能,在此,记录下来,方便日后查阅。
先给大家展示下效果图:
由于功能较简单,这里就直接将代码搬上来吧
<%-- 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实现显示当前日期的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
JS实现显示当前日期的实例代码
- Author -
蚊蚊蚊蚊蚊170624声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@