function dateTransfer(mins) {
return parseInt(mins/60)+":"+(mins%60>9?mins%60:"0"+mins%60);
}
写一个方法把分钟转化为时分,例如:150->02:30
function dateTransfer(mins) {
return parseInt(mins/60)+":"+(mins%60>9?mins%60:"0"+mins%60);
}
function minuteToHour(minute) {
if (typeof minute !== 'string' && typeof minute !== 'number') return `00:00`;
const hour = parseInt(Math.floor(minute / 60));
const minutes = parseInt(minute % 60, 10);
return `${hour > 10 ? hour : `0${hour}`}:${minutes > 10 ? minutes : `0${minutes}`}`;
}
function format(minute = 150) {
minute = parseInt(minute, 10)
const m = Math.floor(minute / 60)
const s = Math.floor(minute % 60)
return [m, s].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
/**
* 转换 分钟转换为时分
*/
var transformTime = (time) => {
if (time > 60*60 || time < 0) return '00:00';
const hour = parseInt(time/60, 10) > 9 ? parseInt(time/60, 10) : '0'+parseInt(time/60, 10)
const min = time%60 > 9 ? time%60 : '0' + time%60;
return hour+':'+min
}
console.log(transformTime(62))
console.log(transformTime(3601))
function addZero(time){
return time<10? 0${time}
:time
}
function convertMinToHour(time){
let min = addZero(time%60);
let hour = addZero(parseInt(time/60));
return ${hour}:${min}
}
/*
* 分钟数 转 时分
*/
function min2Hour (min = 0) {
if (typeof(min) !== 'number' || min < 0) {
console.warn('not a valid number')
return '00:00'
}
let h = Math.floor(min / 60)
let m = min % 60
return `${addZero(h)}:${addZero(m)}`
}
/*
* 不足10补0
*/
function addZero (num) {
return num < 10 ? ('0' + num) : num
}
console.log(
min2Hour(), // 00:00
min2Hour(-10), // 00:00
min2Hour('10'), // 00:00
min2Hour(60), // 01:00
min2Hour(61), // 01:01
min2Hour(150), // 02:30
min2Hour(12345) // 205:45
)
function formatMins(min) {
let hour = Math.floor(min/60);
let minute = min%60;
return `${hour.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}`;
}
学习不打烊,充电加油只为遇到更好的自己,365天无节假日,每天早上5点纯手工发布前端知识点(死磕自己,愉悦大家)。希望大家在这浮夸的前端圈里,保持冷静,坚持每天花20分钟来学习与思考。在这千变万化,类库层出不穷的前端,建议大家不要等到找工作时,才狂刷题,提倡每日学习!欢迎大家关注3+1开源项目!希望大家每人去学习与思考!(不要为了谁而来,要为自己而努力!)