Long型时间轴时间类型转为正常格式时间

旧城等待, 2022-06-18 11:48 297阅读 0赞
  1. /** 转换时间start **/
  2. Date.prototype.format = function (format) {
  3. var o = {
  4. "M+": this.getMonth() + 1,
  5. "d+": this.getDate(),
  6. "h+": this.getHours(),
  7. "m+": this.getMinutes(),
  8. "s+": this.getSeconds(),
  9. "q+": Math.floor((this.getMonth() + 3) / 3),
  10. "S": this.getMilliseconds()
  11. }
  12. if (/(y+)/.test(format)) {
  13. format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  14. }
  15. for (var k in o) {
  16. if (new RegExp("(" + k + ")").test(format)) {
  17. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  18. }
  19. }
  20. return format;
  21. }
  22. function getFormatDateByLong(l, pattern) {
  23. return getFormatDate(new Date(l), pattern);
  24. }
  25. function getSmpFormatDate(date) {
  26. var pattern = "";
  27. pattern = "yyyy-MM-dd hh:mm:ss";
  28. return getFormatDate(date, pattern);
  29. }
  30. function getFormatDate(date, pattern) {
  31. if (date == undefined) {
  32. date = new Date();
  33. }
  34. if (pattern == undefined) {
  35. pattern = "yyyy-MM-dd hh:mm:ss";
  36. }
  37. return date.format(pattern);
  38. }
  39. /** 转换时间end **/
  40. getFormatDateByLong(createtime);

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读