您的位置:首页 > 其它

格式化日期(月和星期)

2017-07-20 11:53 85 查看
// /**
//  * 格式化日期(月和星期)
//  * sFormat:日期的格式(如yy-MM-dd)。年:y,月:M,日:d,时:h,分:m,秒:s
//  * sLanguage: 默认为中文。当为'en'的时候是英文。
//  */
// window.dateFormat=function(date, sFormat, sLanguage){
//     var time = {};
//     time.Year = date.getFullYear();
//     time.TYear = ("" + time.Year).substr(2);
//     time.Month = date.getMonth() + 1;
//     time.TMonth = time.Month < 10 ? "0" + time.Month : time.Month;
//     time.Day = date.getDate();
//     time.TDay = time.Day < 10 ? "0" + time.Day : time.Day;
//     time.Hour = date.getHours();
//     time.THour = time.Hour < 10 ? "0" + time.Hour : time.Hour;
//     time.hour = time.Hour < 13 ? time.Hour : time.Hour;
//     time.Thour = time.hour < 10 ? "0" + time.hour : time.hour;
//     time.Minute = date.getMinutes();
//     time.TMinute = time.Minute < 10 ? "0" + time.Minute : time.Minute;
//     time.Second = date.getSeconds();
//     time.TSecond = time.Second < 10 ? "0" + time.Second : time.Second;
//     time.Millisecond = date.getMilliseconds();
//     time.Week = date.getDay();
//
//     var MMMArrEn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
//         MMMArr = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
//         WeekArrEn = ["Sun", "Mon", "Tue", "Web", "Thu", "Fri", "Sat"],
//         WeekArr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
//         oNumber = time.Millisecond / 1000;
//
//     if (sFormat != undefined && sFormat.replace(/\s/g, "").length > 0) {
//         if (sLanguage != undefined && sLanguage === "en") {
//             MMMArr = MMMArrEn.slice(0);
//             WeekArr = WeekArrEn.slice(0);
//         }
//         sFormat = sFormat.replace(/yyyy/ig, time.Year)
//             .replace(/yyy/ig, time.Year)
//             .replace(/yy/ig, time.TYear)
//             .replace(/y/ig, time.TYear)
//             .replace(/MMM/g, MMMArr[time.Month - 1])
//             .replace(/MM/g, time.TMonth)
//             .replace(/M/g, time.Month)
//             .replace(/dd/ig, time.TDay)
//             .replace(/d/ig, time.Day)
//             .replace(/HH/g, time.THour)
//             .replace(/H/g, time.Hour)
//             .replace(/hh/g, time.Thour)
//             .replace(/h/g, time.hour)
//             .replace(/mm/g, time.TMinute)
//             .replace(/m/g, time.Minute)
//             .replace(/ss/ig, time.TSecond)
//             .replace(/s/ig, time.Second)
//             .replace(/fff/ig, time.Millisecond)
//             .replace(/ff/ig, oNumber.toFixed(2) * 100)
//             .replace(/f/ig, oNumber.toFixed(1) * 10)
//             .replace(/EEE/g, WeekArr[time.Week]);
//     }else {
//         sFormat = time.Year + "-" + time.Month + "-" + time.Day + " " + time.Thour + ":" + time.TMinute + ":" + time.TSecond;
//     }
//     return sFormat;
// };
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: