pFan.date = { //返回时间戳 getTimeStamp:function(){ var timestamp=new Date().getTime(); return timestamp.toString(); }, //时间戳转为日期格式 //@nS为时间戳 getLocalTime: function(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17); }, //@time , 时间 , 如 new Date(‘2013/11/10 0:12:12‘) //@pre , 星期的 前缀,如:周 ,星期 //@ nums ,如:一二三四五六日 getWeek: function (time, pre, nums) { //# 获取星期几 time = typeof time == ‘string‘ ? this.parse(time) : (time || new Date()); pre = pre || ‘星期‘; //周 nums = nums || ‘日一二三四五六‘; return pre + nums[time.getDay()]; }, //@formatType : YYYY, YY, MM //@ time : new Date(‘2013/11/12‘) //@weeks : 日一二三四五六 format: function (formatType, time, weeks) { //格式化输出时间 var pre = ‘0‘, formatType = formatType || ‘YYYY-MM-DD‘, weeks = weeks || ‘日一二三四五六‘, time = time || new Date(); //格式化时间 return (formatType || ‘‘) .replace(/yyyy|YYYY/g, time.getFullYear()) .replace(/yy|YY/g, Tydic.string.addPre(pre, time.getFullYear() % 100), 2) .replace(/mm|MM/g, Tydic.string.addPre(pre, time.getMonth() + 1, 2)) .replace(/m|M/g, time.getMonth() + 1) .replace(/dd|DD/g, Tydic.string.addPre(pre, time.getDate(), 2)) .replace(/d|D/g, time.getDate()) .replace(/hh|HH/g, Tydic.string.addPre(pre, time.getHours(), 2)) .replace(/h|H/g, time.getHours()) .replace(/ii|II/g, Tydic.string.addPre(pre, time.getMinutes(), 2)) .replace(/i|I/g, time.getMinutes()) .replace(/ss|SS/g, Tydic.string.addPre(pre, time.getSeconds(), 2)) .replace(/s|S/g, time.getSeconds()) .replace(/w/g, time.getDay()) .replace(/W/g, weeks[time.getDay()]); } }
时间: 2024-11-10 08:25:41