date.js 945 B

12345678910111213141516171819202122232425262728293031
  1. Date.prototype.format = function(format) {
  2. var o = {
  3. "M+": this.getMonth() + 1,
  4. // month
  5. "d+": this.getDate(),
  6. // day
  7. "h+": this.getHours(),
  8. // hour
  9. "m+": this.getMinutes(),
  10. // minute
  11. "s+": this.getSeconds(),
  12. // second
  13. "q+": Math.floor((this.getMonth() + 3) / 3),
  14. // quarter
  15. "S": this.getMilliseconds()
  16. // millisecond
  17. };
  18. if (/(y+)/.test(format) || /(Y+)/.test(format)) {
  19. format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  20. }
  21. for (var k in o) {
  22. if (new RegExp("(" + k + ")").test(format)) {
  23. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  24. }
  25. }
  26. return format;
  27. };
  28. function timestampFormat(timestamp) {
  29. return (new Date(timestamp)).format("yyyy-MM-dd hh:mm:ss");
  30. }