当前位置:网站首页>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
}
}
边栏推荐
- Here comes the official zero foundation introduction jetpack compose Chinese course!
- ABAP随笔-程序优化笔记
- 亚朵更新招股书:继续推进纳斯达克上市,已提前“套现”2060万元
- 你的PCB地线走的对吗?为什么要有主地?
- Is your PCB ground wire right? Why should we have a master land?
- 网络远程访问树莓派(VNC Viewer)
- Date转换为LocalDateTime
- Six stone programming: the subtlety of application
- How to choose an account opening broker? Is it safe to open an account online now?
- [network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
猜你喜欢

The official Chinese course of zero foundation introduction jetpack compose is coming

ctfshow php的特性

What does the timestamp 90K mean?

10分钟后性能测试瓶颈调优!想进大厂这个必须会

Query the size of each table in the database

Jetpack compose and material you FAQs

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

Intranet penetration token stealing

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

ASEMI超快恢复二极管ES1J参数,ES1J封装,ES1J规格
随机推荐
Right leg drive circuit principle? ECG acquisition is a must, with simulation files!
OutputDebugString instructions and exception handling
【网络通信 -- WebRTC】WebRTC 源码分析 -- PacingController 相关知识点补充
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
Mobile cloud jointly builds the capability base of information innovation cloud and helps the development of China's information innovation industry
QT布局管理器【QVBoxLayout,QHBoxLayout,QGridLayout】
R language uses the image of magick package_ The scale function resizes the image. You can customize the scaling from the angle of width or height
EasyPlayer移动端播放webrtc协议时长按播放页面无法关闭“关于我们”页面
R language plot visualization: plot visualization adds bar chart with error bars with plot in R
网络远程访问树莓派(VNC Viewer)
ERP管理系统的重要性
ABAP essay - material master data interface enhancement
[network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
Is it cost-effective to buy a long-term financial product?
What can the accelerated implementation of digital economy bring to SMEs?
[qsetting and.Ini configuration files] and [create resources.qrc] in QT
ELK日志收集系统部署
DataNode进入Stale状态问题排查
What does websocket do?
Asemi ultrafast recovery diode es1j parameters, es1j package, es1j specification