Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 格式化时间戳 格式:yy/mm/dd hh:MM
- * @param time 时间戳
- * @returns {string} yy/mm/dd hh:MM
- */
- function formatTime(time) {
- var date = new Date(time);
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var days = date.getDate();
- var hours = date.getHours();
- var mins = date.getMinutes();
- return year + '/' + transFormat(month) + '/' + transFormat(days) + ' ' + transFormat(hours) + ':' + transFormat(mins);
- }
- /**
- * 补齐一位数字前面的0,使得输出美观
- * @param value
- * @returns {string}
- */
- function transFormat(value) {
- return ('0' + value).slice(-2);
- }
- document.write(formatTime(1509019200000));
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- /**
- * 格式化时间戳(f带字符串的) 格式:yy/mm/dd hh:MM
- * @param time 时间戳
- * @returns {string} yy/mm/dd hh:MM
- */
- function formatTime(time,value) {
- var date = new Date(time);
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var days = date.getDate();
- var hours = date.getHours();
- var mins = date.getMinutes();
- return value.replace(/(yy)+/i,year).replace(/mm/,transFormat(month)).replace(/dd/i,transFormat(days)).replace(/hh/i,transFormat(hours)).replace(/MM/,transFormat(mins));
- }
- document.write(formatTime(1509019200000,"yyyy/mm/dd hh:MM"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement