格式化UTC时间

格式化时间方法

function formatDate(time, format) {
  var t = new Date(time);
  var tf = function (i) { return (i < 10 ? '0' : '') + i };
  return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
    switch (a) {
      case 'yyyy':
        return tf(t.getFullYear());
        break;
      case 'MM':
        return tf(t.getMonth() + 1);
        break;
      case 'mm':
        return tf(t.getMinutes());
        break;
      case 'dd':
        return tf(t.getDate());
        break;
      case 'HH':
        return tf(t.getHours());
        break;
      case 'ss':
        return tf(t.getSeconds());
        break;
    }
  })
}

处理接口数据

 res.data.forEach((currentVal, index, item) => {
          currentVal.plannedDate = formatDate(currentVal.plannedDate, "yyyy-MM-dd")
        });
posted @ 2025-02-18 14:23  格林格林  阅读(21)  评论(0)    收藏  举报