一·时间戳转换
start_time开始种植时间: 2019-03-08
plant_circle种植时长: 365
需求:我想拿到结束种植时间 _________ 应该是2020-03-07
/**
后台传过来的数据:
start_time开始种植时间: 2019-03-08
plant_circle种植时长: 365
需求:我想拿到结束种植时间 _________ 应该是2020-03-07
**/
sDate(start_time,plant_circle) {
let ss = 24 * 60 * 60 * 1000; //一天的毫秒数86400
let timestamp = new Date(start_time).getTime(); //获取相关时间戳
let date = new Date(ss * plant_circle + timestamp) //加上n天的国际标准日期
let year=date.getFullYear();
let month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
let day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
return year + '-' + month + '-' + day ; //拼接成我们需要的格式返回
},
方法二:
//时间转换—— js
1576462820000 ⇒ 2019-12-16 10:30:20
zhDate(years){
var nowXz = new Date(Number(years)) //时间戳格式——数字类型
let year=nowXz.getFullYear();
let month= nowXz.getMonth()+1<10 ? "0"+(nowXz.getMonth()+1) : nowXz.getMonth()+1;
let day=nowXz.getDate()<10 ? "0"+nowXz.getDate() : nowXz.getDate();
return year + '-' + month + '-' + day ;
},
//日期转时间戳
2019-12-16 10:30:20 ==> 1576462820000
let timeinfo = '2019-12-16 10:30:20';
let timeTT = new Date(timeinfo); //转化标准日期格式
timeTT = timeTT.getTime(); //将日期格式转换成时间戳:
new Date(timeinfo) ==>> ****** timeinfo必须是字符窜 不然会转不了******
方法二:后台转入格式
最终结果——2019-10-21
.
二· 时间钟表 显示
每隔一秒时间走一次 实时变动
//时间
setInterval(updateTime, 1000);
updateTime();
function updateTime() {
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
this.date = date.getDate();
this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var currentTime = this.year + "." + this.month + "." + this.date + " " + this.day+ " "+this.hour + ":" + this.minute + ":" + this.second ;
$("#date").html(currentTime);
}
https://www.cnblogs.com/willingtolove/p/9544877.html
时间转时间戳
时间戳转时间