12345678910111213141516171819202122232425262728293031323334353637 |
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- // 设置时间文案
- const setDuration = (s) => {
- let t = '';
- s = Math.floor(s);
- if (s > -1) {
- let min = Math.floor(s / 60) % 60;
- let sec = s % 60;
- if (min < 10) {
- t += "0";
- }
- t += min + ":";
- if (sec < 10) {
- t += "0";
- }
- t += sec;
- }
- return t
- }
- module.exports = {
- formatTime,
- setDuration
- }
|