国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開(kāi)發(fā) > 正文

js格式化日期時(shí)間的工具方法

2024-04-27 15:15:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
/** * 格式化日期時(shí)間 * @param date * @param pattern 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 */function formatDateTime (date, pattern) { var o = { 'M+': date.getMonth() + 1, 'd+': date.getDate(), 'h+': date.getHours(), 'm+': date.getMinutes(), 's+': date.getSeconds(), 'q+': Math.floor((date.getMonth() + 3) / 3), 'S': date.getMilliseconds() } if (/(y+)/.test(pattern)) { pattern = pattern.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } for (var k in o) { if (new RegExp('(' + k + ')').test(pattern)) { pattern = pattern.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) } } return pattern}console.log(formatDateTime(new Date(), 'yyyy年MM月dd日 hh:mm:ss')) // 2017年02月08日 23:03:38console.log(formatDateTime(new Date(), 'yyyy年M月d日 hh:mm:ss')) // 2017年2月8日 23:03:38console.log(formatDateTime(new Date(1513051932000), 'yyyy年MM月dd日 hh:mm:ss')) // 2017年12月12日 12:12:12console.log(formatDateTime(new Date(1513051932000), 'yyyy年M月d日 hh:mm:ss')) // 2017年12月12日 12:12:12
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 军事| 广南县| 棋牌| 遵化市| 海安县| 双桥区| 宁都县| 安图县| 丰台区| 余干县| 五台县| 内黄县| 禄丰县| 拉萨市| 信丰县| 土默特右旗| 卓资县| 略阳县| 湘西| 铁力市| 右玉县| 文成县| 虹口区| 红桥区| 泸西县| 柘城县| 苏尼特右旗| 隆尧县| 公主岭市| 贵州省| 枝江市| 北川| 华容县| 青川县| 札达县| 高雄市| 本溪| 渑池县| 哈尔滨市| 望奎县| 蓬莱市|