当前位置:网站首页>微信小程序时间戳转化时间格式+时间相减
微信小程序时间戳转化时间格式+时间相减
2022-06-11 16:17:00 【EOPG】
微信小程序时间戳转化时间格式+时间相减
一、时间戳转化为天,时,分,秒
- 新建***util.js,复制下面代码
/** 时间戳格式化天数 **/
function computationTime (total) {
total = total / 1000;
//计算整数天数
let day = parseInt(total / (24 * 60 * 60));
//取得算出天数后剩余的秒数
let afterDay = total - day * 24 * 60 * 60;
//计算整数小时数
let hour = parseInt(afterDay / (60 * 60));
//取得算出小时数后剩余的秒数
let afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60;
//计算整数分
let min = parseInt(afterHour / 60);
//算出分后剩余的秒数
let afterMin = total - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60;
return {
day,
hour,
min,
afterMin: Math.ceil(afterMin)
};
}
module.exports = {
computationTime: computationTime
}
- 在需要的js里面引入
import {
computationTime} from "../../utils/jpxutil.js";
- 直接引用工具函数,输入时间戳返回天,时,分,秒
let time = new Date("2022-06-10 11:40:01");
let time1 = new Date("2022-06-09 10:40:00");
let tt = time.getTime() - time1.getTime();
console.log(computationTime(tt));
二、时间相减转化为天,时,分,秒
与上面的基本一致
上代码
/** 时间相减 */
function timeDifference (newTime, oldTime){
let time1 = new Date(newTime);
let time2 = new Date(oldTime);
return computationTime(time1 - time2);
}
/** 时间戳格式化天数 **/
function computationTime (total) {
total = total / 1000;
//计算整数天数
let day = parseInt(total / (24 * 60 * 60));
//取得算出天数后剩余的秒数
let afterDay = total - day * 24 * 60 * 60;
//计算整数小时数
let hour = parseInt(afterDay / (60 * 60));
//取得算出小时数后剩余的秒数
let afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60;
//计算整数分
let min = parseInt(afterHour / 60);
//算出分后剩余的秒数
let afterMin = total - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60;
return {
day,
hour,
min,
afterMin: Math.ceil(afterMin)
};
}
module.exports = {
computationTime: computationTime,
timeDifference: timeDifference
}
边栏推荐
猜你喜欢

【剑指Offer】22.链表中倒数第K节点

web网页设计实例作业 ——河南美食介绍(4页) web期末作业设计网页_甜品美食大学生网页设计作业成品

Ruiji takeout project (III) employee management business development

Collection | can explain the development and common methods of machine learning!

The flat life of older farmers from Beijing to Holland

PostgreSQL startup process

Streaking? Baa!

Implementation of VGA protocol based on FPGA

再聊数据中心网络

Opengauss database JDBC environment connection configuration (eclipse)
随机推荐
leetcode-141. Circular linked list
Pyqt5 enables the qplaintextedit control to support line number display
类的 prototype 属性和__proto__属性,类原型链有两条继承路线
想学好ArrayList,看完这篇就够了
[从零开始学习FPGA编程-18]:快速入门篇 - 操作步骤2-6- VerilogHDL时序电路语法分析(以计数器为例)
Interview classic question: how to do the performance test? [Hangzhou multi surveyors] [Hangzhou multi surveyors \wang Sir]
TC8:UDP_MessageFormat_01-02
项目工作区创建步骤-泽众AR自动化测试工具
面试高频算法题---最长回文子串
Transfer learning
Laravel 8 realizes database backup through task scheduling
CLP information - No. 1 central document on Strengthening Rural Revitalization financial services
After reading the book reading methods
【剑指Offer】21.调整数组顺序使奇数位于偶数前面
one hundred and twenty-three thousand one hundred and twenty-three
Class and__ proto__ Property, the class prototype chain has two inheritance routes
MySQL quick start instance (no loss)
Elk enterprise log analysis system
laravel8 实现签到功能案例
Opengauss database ODBC environment connection configuration (Windows)