中国标准时间转换为yyyy-MM-dd

若此时的时间格式为

则使用  createTime = new Date(createTime); 将时间转换为中国标准时间

private formatDate(date) {
    let formatDate;
    formatDate = new Date(date);
    formatDate =
      formatDate.getFullYear() +
      "-" +
      (formatDate.getMonth() + 1 > 9
        ? formatDate.getMonth() + 1
        : "0" + (formatDate.getMonth() + 1)) +
      "-" +
      (formatDate.getDate() > 9
        ? formatDate.getDate()
        : "0" + formatDate.getDate()) +
      "  " +
      (formatDate.getHours() > 9
        ? formatDate.getHours()
        : "0" + formatDate.getHours()) +
      ":" +
      (formatDate.getMinutes() > 9
        ? formatDate.getMinutes()
        : "0" + formatDate.getMinutes()) +
      ":" +
      (formatDate.getSeconds() > 9
        ? formatDate.getSeconds()
        : "0" + formatDate.getSeconds());
    return formatDate;
  }

效果图

猜你喜欢

转载自blog.csdn.net/qq_34607371/article/details/86150223
今日推荐