This commit is contained in:
SelfRidicule 2024-03-04 15:49:05 +08:00
parent cba08d6f3f
commit 79d06953b0
2 changed files with 79 additions and 65 deletions

View File

@ -3,6 +3,8 @@ import {
meetingRoomBookedRecordRq meetingRoomBookedRecordRq
} from "../../../../api/meeting/meetingRoom.js" } from "../../../../api/meeting/meetingRoom.js"
import {selfFormatTimeReturnSecond59} from "../../../../utils/util.js"
Page({ Page({
/** /**
@ -30,8 +32,9 @@ Page({
// 选择-结束时间 // 选择-结束时间
onInputEndTime(event) { onInputEndTime(event) {
let _this = this; let _this = this;
this.setData({ this.setData({
endTime: _this.addSeconds(event.detail , 59), endTime: new Date(selfFormatTimeReturnSecond59(event.detail)).getTime(),
}); });
}, },
@ -81,10 +84,6 @@ Page({
}) })
}, },
// 添加指定秒数
addSeconds(time , seconds) {
return new Date(time.setSeconds(time.getSeconds() + seconds)).getTime();
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载

View File

@ -1,87 +1,102 @@
//返回 例 2017 //返回 例 2017
const formatYear = data => { const formatYear = data => {
var date = data.date; var date = data.date;
var types = data.types; var types = data.types;
const year = date.getFullYear() const year = date.getFullYear()
const month = date.getMonth() + 1 const month = date.getMonth() + 1
const day = date.getDate() const day = date.getDate()
const hour = date.getHours() const hour = date.getHours()
const minute = date.getMinutes() const minute = date.getMinutes()
const second = date.getSeconds() const second = date.getSeconds()
if (types == 'year') { if (types == 'year') {
return [year].map(formatNumber).join('-') return [year].map(formatNumber).join('-')
} else if (types == 'month') { } else if (types == 'month') {
return [month].map(formatNumber).join('-') return [month].map(formatNumber).join('-')
} else if (types == 'day') { } else if (types == 'day') {
return [day].map(formatNumber).join('-') return [day].map(formatNumber).join('-')
} }
} }
//返回 例 12月02日 //返回 例 12月02日
const formatDate2 = date => { const formatDate2 = date => {
const month = date.getMonth() + 1 const month = date.getMonth() + 1
const day = date.getDate() const day = date.getDate()
return [month].map(formatNumber) + '月' + [day].map(formatNumber) + '日' return [month].map(formatNumber) + '月' + [day].map(formatNumber) + '日'
} }
//返回 例 2017-12-12 //返回 例 2017-12-12
const formatDate = date => { const formatDate = date => {
const year = date.getFullYear() const year = date.getFullYear()
const month = date.getMonth() + 1 const month = date.getMonth() + 1
const day = date.getDate() const day = date.getDate()
const hour = date.getHours() const hour = date.getHours()
const minute = date.getMinutes() const minute = date.getMinutes()
const second = date.getSeconds() const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') return [year, month, day].map(formatNumber).join('-')
} }
//返回 例 2017--12-12 12:30:00 //返回 例 2017-12-12 12:30:00
const formatTime = date => { const formatTime = date => {
const year = date.getFullYear() const year = date.getFullYear()
const month = date.getMonth() + 1 const month = date.getMonth() + 1
const day = date.getDate() const day = date.getDate()
const hour = date.getHours() const hour = date.getHours()
const minute = date.getMinutes() const minute = date.getMinutes()
const second = date.getSeconds() const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
} }
//返回 例 12-12 12:30:00 //返回 例 12-12 12:30:00
const formatTime2 = date => { const formatTime2 = date => {
const month = date.getMonth() + 1 const month = date.getMonth() + 1
const day = date.getDate() const day = date.getDate()
const hour = date.getHours() const hour = date.getHours()
const minute = date.getMinutes() const minute = date.getMinutes()
return [month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':') return [month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
} }
//返回 小时12:00:00 //返回 小时12:00:00
const formatHour = data => { const formatHour = data => {
var date = data.date; var date = data.date;
var types = data.types; var types = data.types;
const hour = date.getHours() const hour = date.getHours()
const minute = date.getMinutes() const minute = date.getMinutes()
const second = date.getSeconds() const second = date.getSeconds()
if (types == 'hour') { if (types == 'hour') {
return [hour].map(formatNumber) return [hour].map(formatNumber)
} else if (types == 'minute') { } else if (types == 'minute') {
return [minute].map(formatNumber).join('-') return [minute].map(formatNumber).join('-')
} else if (types == 'second') { } else if (types == 'second') {
return [second].map(formatNumber) return [second].map(formatNumber)
} }
} }
//返回 指定秒数59 2017-12-12 12:30:59
function selfFormatTimeReturnSecond59(time) {
let date = new Date(time);
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
let hour = date.getHours()
let minute = date.getMinutes()
let second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, '59'].map(formatNumber).join(':')
}
const formatNumber = n => { const formatNumber = n => {
n = n.toString() n = n.toString()
return n[1] ? n : '0' + n return n[1] ? n : '0' + n
} }
module.exports = { module.exports = {
formatTime: formatTime, formatTime: formatTime,
formatDate: formatDate, formatDate: formatDate,
formatYear: formatYear, formatYear: formatYear,
formatDate2: formatDate2, formatDate2: formatDate2,
formatHour: formatHour, formatHour: formatHour,
formatTime2: formatTime2 formatTime2: formatTime2,
selfFormatTimeReturnSecond59
} }