- js获取系统当前时间,并转换为yyyy-mm-dd hh:mm:ss格式
方法一:
var currentDate = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
该方法在ie低版本浏览器会存在兼容性问题,推荐第二种方法
方法二:
function currentDate(date){var year &#61; date.getFullYear(); var month &#61; date.getMonth() &#43; 1; var day &#61; date.getDate(); var hours &#61; date.getHours(); var minutes &#61; date.getMinutes(); var seconds &#61; date.getSeconds(); if (month >&#61; 1 && month <&#61; 9) {month &#61; "0" &#43; month;}if (day >&#61; 0 && day <&#61; 9) {day &#61; "0" &#43; day;}if (hours >&#61; 0 && hours <&#61; 9) {hours &#61; "0" &#43; hours;}if (minutes >&#61; 0 && minutes <&#61; 9) {minutes &#61; "0" &#43; minutes;}if (seconds >&#61; 0 && seconds <&#61; 9) {seconds &#61; "0" &#43; seconds;}var currentFormatDate &#61; year &#43; "-" &#43; month &#43; "-" &#43; day &#43; " " &#43; hours &#43; ":" &#43; minutes &#43; ":" &#43; seconds;return currentFormatDate;}currentDate(new Date())
- js获取星期几&#xff1a;
function getWeekDate(now) {var day &#61; now.getDay();var weeks &#61; ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];var week &#61; weeks[day];return week;}getWeekDate(new Date());