当前位置:网站首页>Wechat applet timestamp conversion time format + time subtraction
Wechat applet timestamp conversion time format + time subtraction
2022-06-11 16:33:00 【EOPG】
Wechat applet timestamp conversion time format + Time minus
One 、 The timestamp is converted to days , when , branch , second
- newly build ***util.js, Copy the following code
/** Timestamp format days **/
function computationTime (total) {
total = total / 1000;
// Calculate integer days
let day = parseInt(total / (24 * 60 * 60));
// Gets the number of seconds remaining after the number of days is calculated
let afterDay = total - day * 24 * 60 * 60;
// Calculate integer hours
let hour = parseInt(afterDay / (60 * 60));
// Gets the number of seconds remaining after the calculated hours
let afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60;
// Calculate integral minutes
let min = parseInt(afterHour / 60);
// Calculate the number of seconds left after minutes
let afterMin = total - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60;
return {
day,
hour,
min,
afterMin: Math.ceil(afterMin)
};
}
module.exports = {
computationTime: computationTime
}
- In need of js Introduced inside
import {
computationTime} from "../../utils/jpxutil.js";
- Direct reference to tool functions , Enter timestamp return days , when , branch , second
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));
Two 、 Subtracting time into days , when , branch , second
Basically consistent with the above
Code up
/** Time minus */
function timeDifference (newTime, oldTime){
let time1 = new Date(newTime);
let time2 = new Date(oldTime);
return computationTime(time1 - time2);
}
/** Timestamp format days **/
function computationTime (total) {
total = total / 1000;
// Calculate integer days
let day = parseInt(total / (24 * 60 * 60));
// Gets the number of seconds remaining after the number of days is calculated
let afterDay = total - day * 24 * 60 * 60;
// Calculate integer hours
let hour = parseInt(afterDay / (60 * 60));
// Gets the number of seconds remaining after the calculated hours
let afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60;
// Calculate integral minutes
let min = parseInt(afterHour / 60);
// Calculate the number of seconds left after minutes
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
}
边栏推荐
- Leetcode 1974. Minimum time to type words using a special typewriter (yes, once)
- After reading the book reading methods
- leetcode-141. Circular linked list
- 09 Minimum Spanning Tree highway
- 2022 safety officer-a certificate test question simulation test question bank simulation test platform operation
- pycharm和anaconda的基础上解决Jupyter连接不上Kernel(内核)的问题--解决方案1
- Pyqt5 enables the qplaintextedit control to support line number display
- List和Set存取元素的差异
- The flat life of older farmers from Beijing to Holland
- 2022 simulated examination question bank and simulated examination for crane driver (limited to bridge crane)
猜你喜欢

【pytest学习】pytest 用例执行失败后其他不再执行

Composition of JVM

2022熔化焊接与热切割上岗证题目及模拟考试

485 days, 21 experiences of my remote office sharing | community essay solicitation

JDBC debugging error, ask for guidance

为什么芯片设计也需要「匠人精神」?

Ruiji takeout project (III) employee management business development

Text driven for creating and editing images (with source code)

Interview high frequency algorithm question --- longest palindrome substring

How the autorunner automated test tool creates a project -alltesting | Zezhong cloud test
随机推荐
Oracle 分析函数 over 和MySQL 实现类似效果写法
What is a generic? Why use generics? How do I use generics? What about packaging?
leetcode463. 岛屿的周长(简单)
【opencvsharp】opencvsharp_samples.core示例代码笔记
2022 R1 quick opening pressure vessel operation test question bank and simulation test
Enterprise purchase, sales and inventory management system based on SSM framework [source code + database + design]
[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers
搜索与图论:Dijkstra求最短路 I—Dijkstra(最短路径)
Time processing logic for the last 7 days, the last 10 days, and the last 90 days
【剑指Offer】22.链表中倒数第K节点
Question ac: Horse Vaulting in Chinese chess
jsp页面初始加载方式
JVM 的组成
List和Set存取元素的差异
Ruiji takeout project (III) employee management business development
Composition of JVM
项目无法加载nacos配置中心的配置文件问题
数据库全量SQL分析与审计系统性能优化之旅
什么是rs邮票纸?
Pyqt5 enables the qplaintextedit control to support line number display