当前位置:网站首页>Wechat applet: time selector for the estimated arrival date of the hotel
Wechat applet: time selector for the estimated arrival date of the hotel
2022-06-23 17:25:00 【_ Lan】
This function only shows the afternoon 14:00 To the next day 06:00 Time period , When Click the time selector in the morning , The list of selectors defaults from 14:00 From the beginning to the next day 06:00 Time period , When Click the time selector in the afternoon , The list of selectors defaults to From the current time To the next day 06:00 Time period ,
design sketch :


1, Layout
2,js Logic

/** Life cycle function -- Monitor page display */
onShow: function () {
this.obtainTime();
},
/** Get the time period to arrive at the hotel */
obtainTime(){
let hour = getToDay().date;
let hou = hour.getHours();
if(hou < 14){
let list = ['14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00',' The next day 00:00',' The next day 01:00',' The next day 02:00',' The next day 03:00',' The next day 04:00',' The next day 05:00',' The next day 06:00'];
this.setData({
timeSelection:list
});
}else{
let list = [];
// for Cyclic 3 Conditions can be omitted , There is no judgment condition for exiting the loop , Must use break Statement exit loop , Otherwise it's a dead cycle :
for(; ;) {
hour.setHours(hour.getHours() + 1);
let hh = hour.getHours();
if(hh == 7){
break; // adopt if Judge to exit the loop
}
if (hh < 10) hh = ' The next day 0' + hh +':00';
if (hh > 10) hh = hh +':00';
list.push(hh)
}
this.setData({
timeSelection:list
});
}
},
/** The estimated arrival time is displayed */
bindTimeChange(e){
this.setData({
index2:e.detail.value
})
}
3, Year, day, hour, minute and second packaging

/** Split date format */
export function 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 ,hour, minute, second].map(formatNumber)
}
/** Interception date */
export function formatDate( time_ , format_ ) {
const date = time_.split(" ");
const dateArr = date[0].split("-");
const timeArr = date[1].split(":");
switch (format_) {
case 'yy-mm':
return `${ dateArr[0] }-${ dateArr[1] }`
break;
case 'yy-mm-dd':
return `${ dateArr[0] }-${ dateArr[1] }-${ dateArr[2] }`
break;
case 'yy-mm-dd hh:mm':
return `${ dateArr[0] }-${ dateArr[1] }-${ dateArr[2] } ${ timeArr[0] }:${ timeArr[1] }`
break;
default: return false; break;
}
}
/** Convert the time difference into hh:mm Format */
export function calculateTime( s_ , e_ , format) {
let s_times = new Date(s_.replace(/-/g,'/').replace(/-/g,'/')).getTime();
let e_times = new Date(e_.replace(/-/g,'/').replace(/-/g,'/')).getTime();
let durs = ( e_times - s_times );
let hour = durs/1000/60/60;
hour = Math.floor(hour);
let minute = Math.floor((durs - hour*1000*60*60)/1000/60);
let second = Math.floor((durs - hour*1000*60*60 - minute*1000*60)/1000);
return [hour,minute,second].map(formatNumber)
}
// format
function formatNumber(n) {
n = n.toString()
return n.length >= 2 ? n : '0' + n
}
/** Get today's date */
export function getToDay() {
let date = new Date();
let y = date.getFullYear();
let m = date.getMonth() + 1;
let d = date.getDate();
let hh = date.getHours();
let mm = date.getMinutes();
let ss = date.getSeconds();
date.setDate(date.getDate() + 1); // Future days 1 For tomorrow ,2,3,4,5 It represents the next few days
let yyy = date.getFullYear();
let mmm = date.getMonth() + 1;
let ddd = date.getDate();
let today = `${ y }-${ formatNumber(m) }-${ formatNumber(d) }`; // Specific date
let currentDate = `${ y }-${ formatNumber(m) }-${ formatNumber(d) }`; // The current date
let future = `${ yyy }-${ formatNumber(mmm) }-${ formatNumber(ddd) }`; // Future dates
let n = today + ` ${ formatNumber(hh) }:${ formatNumber(mm) }:${ formatNumber(ss) }`; // current time
return {
date,
y,
m,
d,
currentDate,
future,
today,
hh,
mm,
n
}
}
边栏推荐
- 电感参数有哪些?怎么选择电感?
- Is your PCB ground wire right? Why should we have a master land?
- Date转换为LocalDateTime
- TensorRT Paser加载onnx 推理使用
- 美团三面:聊聊你理解的Redis主从复制原理?
- [qsetting and.Ini configuration files] and [create resources.qrc] in QT
- What is an abstract class? How to define abstract classes?
- ABAP essay - material master data interface enhancement
- Practice sharing of chaos engineering in stability management of cloud native Middleware
- QT布局管理器【QVBoxLayout,QHBoxLayout,QGridLayout】
猜你喜欢

The Google play academy team PK competition is in full swing!

Intel arc A380 graphics card message summary: the entry-level price products of running point and bright driving need to be optimized

Can the asemi fast recovery diodes RS1M, us1m and US1G be replaced with each other

Redis cluster operation method

公司招了个五年经验的测试员,见识到了真正的测试天花板

JS常见的报错及异常捕获

使用Jmeter进行性能测试及性能监控平台搭建

The company recruited a tester with five years' experience and saw the real test ceiling

Huawei mobile phones install APK through ADB and prompt "the signature is inconsistent. The application may have been modified."
![[qsetting and.Ini configuration files] and [create resources.qrc] in QT](/img/67/85a5e7f6ad4220600acd377248ef46.png)
[qsetting and.Ini configuration files] and [create resources.qrc] in QT
随机推荐
华为手机通过adb安装APK提示“签名不一致,该应用可能已被修改”
AMQP协议
QT layout manager [qvboxlayout, qhboxlayout, qgridlayout]
Tupu software builds smart city with lightweight modeling
Digital twin excavator of Tupu software realizes remote control
Tensorrt Paser loading onnx inference use
【网络通信 -- WebRTC】WebRTC 源码分析 -- PacingController 相关知识点补充
[qsetting and.Ini configuration files] and [create resources.qrc] in QT
C. Phoenix and Towers-Codeforces Global Round 14
What is an abstract class? How to define abstract classes?
炒股买股票需要怎么选择呢?安全性不错的?
Is your PCB ground wire right? Why should we have a master land?
The company recruited a tester with five years' experience and saw the real test ceiling
你的PCB地线走的对吗?为什么要有主地?
供求两端的对接将不再是依靠互联网时代的平台和中心来实现的
千呼万唤,5G双卡双通到底有多重要?
qYKVEtqdDg
The evolution of social structure and capital system brought about by the yuan universe
电感参数有哪些?怎么选择电感?
JMeter stress testing tutorial