<script type="text/javascript"> var a = '<%= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) %>'; document.write("服务器时间: " + a + "</br></br>"); var b = new Date(); document.write("本地时间: " + formatDate("yyyy-MM-dd HH:mm:ss",b)); function formatDate(pattern,date) { function formatNumber(data,format) { format = format.length; data = data || 0; return format == 1 ? data : (data=String(Math.pow(10,format)+data)).substr(data.length-format); } return pattern.replace(/([yMdHms])\1*/g,function(format){ switch(format.charAt()) { case 'y' : return formatNumber(date.getFullYear(),format); case 'M' : return formatNumber(date.getMonth()+1,format); case 'd' : return formatNumber(date.getDate(),format); case 'w' : return date.getDay()+1; case 'H' : return formatNumber(date.getHours(),format); case 'm' : return formatNumber(date.getMinutes(),format); case 's' : return formatNumber(date.getSeconds(),format); } }); } </script>