本文介绍: 【代码时间转换成年月日时分秒。

1.使用new Date()将时间戳转换成时间

var date = new Date(time);

2.提取

var Y = date.getFullYear() + '-';

3.提取判断是否需要补0操作

var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';

4.获取判断是否需要补0操作

var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

5.获取判断是否需要补0操作

var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';

6.获取判断是否需要补0操作

var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());

7.获取判断是否需要补0操作

var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());

代码

time(time){
			var date = new Date(time);
			var Y = date.getFullYear() + '-'; 
			var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
			var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
			var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
			var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
			var time1 = Y + M + D + h + m;
		}

原文地址:https://blog.csdn.net/weixin_61964186/article/details/129620558

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_16667.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注