在使用云函数导入excel时发现excel中的时间是44044.7673611111,需要处理之后才可以正常使用,实际使用中以下方法 在云函数和小程序中调用时间差了8个小时,需按需调用,
excel文件导入请看 微信小程序 - excel通过云函数导入云数据库
/* excel 时间转换
* num 44044.7673611111(2020/8/1 18:25:00)
* return 2020/08/01 18:25:00
*/
Jh_excelDateToYMDHMS(num) {
var utc_days = Math.floor(num - 25569);
var utc_value = utc_days * 86400;
var date_info = new Date(utc_value * 1000);
var fractional_day = num - Math.floor(num) + 0.0000001;
var total_seconds = Math.floor(86400 * fractional_day);
var seconds = total_seconds % 60;
total_seconds -= seconds;
var hours = Math.floor(total_seconds / (60 * 60));
var minutes = Math.floor(total_seconds / 60) % 60;
//中国标准时间
var time = new Date(date_info.getFullYear(), date_info.getMonth(), date_info.getDate(), hours, minutes, seconds);
// console.log(time); Sat Aug 01 2020 18:25:00 GMT+0800 (中国标准时间)
// return time
var dateStr = new Date(time).toJSON();
//小程序调用
var date = new Date(+new Date(dateStr) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
// //云函数调用
// var date = new Date(+new Date(dateStr)).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
var newTime = date.replace(/-/g, '/');
return newTime
},
调用
//2020/8/1 18:25:00
var num = 44044.7673611111
var time7 = this.Jh_excelDateToYMDHMS(num)
console.log(time7);
//输出
2020/08/01 18:25:00
网友评论