前端 年月日 时间戳 中国标准时间 国际标准时间 转换

嘀嘀嘀  ~   前端日期相互转换来了

1.  国际标准时间转年月日   

方法一:

         2022-09-30T12:20:00.000Z 为国际标准时间 (国际标准时间和年月日时差为8个小时)

        转换完成  结果为   2022.09.30   20:20:00


methods:{
	addZero(num) {
	    return num < 10 ? '0' + num : num;
	},
	formatDateTime(date) {
	    const time = new Date(Date.parse(date));
		time.setTime(time.setHours(time.getHours()));
		const Y = time.getFullYear() + '.';
		const M = this.addZero(time.getMonth() + 1) + '.';
	    const D = this.addZero(time.getDate()) + ' ';
		const h = this.addZero(time.getHours()) + ':';
		const m = this.addZero(time.getMinutes()) + ':';
		const s = this.addZero(time.getSeconds());
		return Y + M + D + h + m + s;
	},
}

方法二:

        下面方法只是简单分割然后重组  格式化

        2022-09-30T12:20:00.000Z 转换为年月日 就是2022-09-30  12:20:00

  formateDate(date) {
    const arr = date.split('T');
    const d = arr[0];
    const darr = d.split('-');

    const t = arr[1];
    const tarr = t.split('.000');
    const marr = tarr[0].split(':');

    const dd =
      parseInt(darr[0]) +
      '-' +
      parseInt(darr[1]) +
      '-' +
      parseInt(darr[2]) +
      ' ' +
      parseInt(marr[0]) +
      ':' +
      parseInt(marr[1]) +
      ':' +
      parseInt(marr[2]);
    return dd;
  }

转自:如何格式化和转换后台给的时间戳(2020-02-22T16:00:00.000Z)为标准的时间格式_const.的博客-CSDN博客

2.  中国标准时间转换年月日

function switchDate(standardTime) {
  if (standardTime != "") {
    let a = standardTime;
    var Month = a.getMonth() + 1;
    var MonthDate;
    var DayDate = a.getDate();
    var Day;
    if (Month < 10) {
      MonthDate = '0' + Month;
    } else {
      MonthDate = Month;
    }
    if (DayDate < 10) {
      Day = '0' + DayDate;
    } else {
      Day = DayDate;
    }
    var datetime = a.getFullYear() + "-" + MonthDate + "-" + Day;
    console.log(datetime)
    return datetime
  }
}

中国标准时间standardTime =  Sat Jan 01 1994 00:00:00 GMT+0800 (中国标准时间) 转之后是datetime = 1994-01-01

转自:中国标准时间转日期YYYY-MM-DD_M_SSY的博客-CSDN博客_中国标准时间怎么转成日期

3.时间戳转换年月日

        转载:

时间戳转换、获取当前时间年月日 - vaelcy - 博客园

4.中国标准时间转换年月日

        转载:

年月日转换为标准时间_imkaifan的博客-CSDN博客_年月日转标准时间

5.可以查看  安装 | Day.js中文网

下载js文件到项目   方便使用

欢迎大家前来探讨

如有侵权,请联系删除

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值