当前位置:网站首页>Time format method on the official demo of uniapp
Time format method on the official demo of uniapp
2022-06-13 04:18:00 【Twinkle, twinkle, twinkle, twinkle, twinkle, twinkle, twinkle, 】
function formatTime(time) {
if (typeof time !== 'number' || time < 0) {
return time
}
var hour = parseInt(time / 3600)
time = time % 3600
var minute = parseInt(time / 60)
time = time % 60
var second = time
return ([hour, minute, second]).map(function(n) {
n = n.toString()
return n[1] ? n : '0' + n
}).join(':')
}
function formatLocation(longitude, latitude) {
if (typeof longitude === 'string' && typeof latitude === 'string') {
longitude = parseFloat(longitude)
latitude = parseFloat(latitude)
}
longitude = longitude.toFixed(2)
latitude = latitude.toFixed(2)
return {
longitude: longitude.toString().split('.'),
latitude: latitude.toString().split('.')
}
}
var dateUtils = {
UNITS: {
' year ': 31557600000,
' month ': 2629800000,
' God ': 86400000,
' Hours ': 3600000,
' minute ': 60000,
' second ': 1000
},
humanize: function(milliseconds) {
var humanize = '';
for (var key in this.UNITS) {
if (milliseconds >= this.UNITS[key]) {
humanize = Math.floor(milliseconds / this.UNITS[key]) + key + ' front ';
break;
}
}
return humanize || ' just ';
},
format: function(dateStr) {
var date = this.parse(dateStr)
var diff = Date.now() - date.getTime();
if (diff < this.UNITS[' God ']) {
return this.humanize(diff);
}
var _format = function(number) {
return (number < 10 ? ('0' + number) : number);
};
return date.getFullYear() + '/' + _format(date.getMonth() + 1) + '/' + _format(date.getDate()) + '-' +
_format(date.getHours()) + ':' + _format(date.getMinutes());
},
parse: function(str) { // take "yyyy-mm-dd HH:MM:ss" Format string , Turn into a Date object
var a = str.split(/[^0-9]/);
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
}
};
export {
formatTime,
formatLocation,
dateUtils
}
边栏推荐
- Sword finger offer 11 Minimum number of rotation array - binary lookup
- Lambda termination operation Max & min
- Unity shader learning 004 shader debugging platform difference third-party debugging tools
- El expression
- SCM: introduction and operation of EEPROM
- Single chip microcomputer: pcf8591 application program
- SQL advanced challenge (1 - 5)
- [test development] installation of test management tool Zen path
- Modeling discussion series 143 data processing, analysis and decision system development
- 出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
猜你喜欢
Principle, composition and functions of sensors of Dajiang UAV flight control system
[test development] basic concepts related to testing
Ego planner code analysis ----cmakelists Txt and package xml
Hugo 博客搭建教程
Value of line height
[test development] advanced part - Classification of various test technologies
Single chip microcomputer: MODBUS multi computer communication program design
Uni app dynamic add style dynamic bind background image invalid
Real time requirements for 5g China Unicom repeater network management protocol
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-3 personal solutions
随机推荐
[test development] advanced part - Classification of various test technologies
解答私信@田田WX //2022-6-12 C语言 51单片机LED模拟交通灯
1-72 convert string to decimal integer
LVS four layer load balancing cluster (3) cluster function classification - HPC
Redis data persistence
Redis-HyperLogLog-基数统计算法
Lambda end operation find and match findfirst
高等数学(第七版)同济大学 习题1-2 个人解答
Billions of data to determine whether the element exists
Common ways to traverse map sets
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
EGO planner论文翻译
Consolidated figures
[test development] use case
Use the visual studio code terminal to execute the command, and the prompt "because running scripts is prohibited on this system" will give an error
Introduction and use of ES6
MCU: pcf8591 hardware interface
Zoom and move the H5 part of the mobile end
Mongodb compass connects to the Alibaba cloud remote server database or reports an error occurred while loading instance info: command hostinfo req
Lambda termination operation find and match nonematch