您的位置 首页 php

页面显示日期及其格式化

9306644254df48089b2c37952333dfbb

一、Thymeleaf显示当前日期

 日期:[[${#dates.format(new java.util.Date().getTime(), 'yyyy年MM月dd日')}]]  

二、thymeleaf获取参数的值

startDate是传递的参数

 [[${param.startDate}]]  

三、JavaScript

 // 字符串 转日期格式,strDate要转为日期格式的字符串function getDate(strDate){ var date =  eval ('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,  function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')'); return date;}  
 //格式化日期function formatDate(date) {console.log(date);// date = new Date();date = new Date(Date.parse(date.replace(/-/g, "/"))); //转换成Data();console.log(date);var y = date.getFullYear();console.log(y);var m = date.getMonth() + 1;m = m < 10 ? '0' + m : m;var d = date.getDate();d = d < 10 ? ('0' + d) : d;return y + '年' + m + '月';}  
 //接收传递过来的参数值函数function GetQueryString(sProp) {   var re = new RegExp("[&,?]" + sProp + "=([^//&]*)", "i");   var a = re.exec(document.location.search);   if (a == null)       return "";   return a[1];}  
 //日期id为hrq显示**年**月window.onload = function(){document.getElementById('hrq').innerHTML=formatDate(GetQueryString("startDate"));}  

文章来源:智云一二三科技

文章标题:页面显示日期及其格式化

文章地址:https://www.zhihuclub.com/31081.shtml

关于作者: 智云科技

热门文章

网站地图