Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

时间格式化 #2

Open
ruanshr opened this issue Aug 28, 2016 · 0 comments
Open

时间格式化 #2

ruanshr opened this issue Aug 28, 2016 · 0 comments

Comments

@ruanshr
Copy link
Owner

ruanshr commented Aug 28, 2016

// 时间格式化
function formatDate(date,format) {
date = date instanceof Date && date || new Date(date);
var year = date.getFullYear();
var month = date.getMonth();
var month1 = month + 1;
var day = date.getDate();
var weekDay = date.getDay();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
return (format || '')
.replace(/yyyy/g, year)
.replace(/yy/g, (year + '').substring(2))
.replace(/MM/g, month1 < 10 ? '0' + month1 : month1)
.replace(/m/g, month1)
.replace(/dd/g, day < 10 ? '0' + day : day)
.replace(/d/g, day)
.replace(/HH/g,hours < 10 ? '0' + hours : hours)
.replace(/H/g,hours)
.replace(/mm/g,minutes < 10 ? '0' + minutes : minutes)
.replace(/m/g,minutes)
.replace(/ss/g,seconds < 10 ? '0' + seconds : seconds)
.replace(/s/g,seconds);
}

@ruanshr ruanshr mentioned this issue Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant