You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 vuosi sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var date = {};
  2. var formatNumber = function(n) {
  3. n = n.toString()
  4. return n[1] ? n : '0' + n
  5. }
  6. var regYear = getRegExp("(y+)", "i");
  7. var dateFormat = function(timestamp, format) {
  8. if (!format) {
  9. format = "yyyy-MM-dd hh:mm:ss";
  10. }
  11. timestamp = parseInt(timestamp);
  12. var realDate = getDate(timestamp);
  13. function timeFormat(num) {
  14. return num < 10 ? '0' + num : num;
  15. }
  16. var date = [
  17. ["M+", timeFormat(realDate.getMonth() + 1)],
  18. ["d+", timeFormat(realDate.getDate())],
  19. ["h+", timeFormat(realDate.getHours())],
  20. ["m+", timeFormat(realDate.getMinutes())],
  21. ["s+", timeFormat(realDate.getSeconds())],
  22. ["q+", Math.floor((realDate.getMonth() + 3) / 3)],
  23. ["S+", realDate.getMilliseconds()],
  24. ];
  25. var reg1 = regYear.exec(format);
  26. if (reg1) {
  27. format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length));
  28. }
  29. for (var i = 0; i < date.length; i++) {
  30. var k = date[i][0];
  31. var v = date[i][1];
  32. var reg2 = getRegExp("(" + k + ")").exec(format);
  33. if (reg2) {
  34. format = format.replace(reg2[1], reg2[1].length == 1 ?
  35. v : ("00" + v).substring(("" + v).length));
  36. }
  37. }
  38. return format;
  39. }
  40. date.anyuFormat = function(timesS, format) {
  41. return dateFormat(timesS * 1000, format);
  42. }
  43. date.dateFormat = dateFormat;
  44. module.exports = date;