当前位置:网站首页>How to use Moment. JS to check whether the current time is between 2 times
How to use Moment. JS to check whether the current time is between 2 times
2022-07-06 14:48:00 【javail】
problem :
Say the current time is 09:34:00
( hh:mm:ss
), and I have two other times in two variables: Suppose the current time is 09:34:00
( hh:mm:ss
), I have two other times in two variables :
var beforeTime = '08:34:00', afterTime = '10:34:00';
How do I use Moment.JS to check whether the current time is between beforeTime
and afterTime
? How to use Moment.JS Check whether the current time is beforeTime
and afterTime
Between ?
I've seen isBetween()
, and I've tried to use it like: I have seen isBetween()
, I've tried to use it like this :
moment().format('hh:mm:ss').isBetween('08:27:00', '10:27:00')
but that doesn't work because as soon as I format the first (current time) moment into a string, it's no longer a moment object. But it doesn't work , Because once I will be the first ( current time ) The time is formatted as a string , It is no longer an object of time .I've also tried using: I've also tried to use :
moment('10:34:00', 'hh:mm:ss').isAfter(moment().format('hh:mm:ss')) && moment('08:34:00', 'hh:mm:ss').isBefore(moment().format('hh:mm:ss'))
but I get false
, because again when I format the current time, it's no longer a moment. But I got false
, Because when I format the current time again , It is no longer a moment .
How do I get this to work? How can I make this work ?
Solution :
Reference resources : https://stackoom.com/en/question/2RsV5边栏推荐
猜你喜欢
后台登录系统,JDBC连接数据库,做小案例练习
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
“人生若只如初见”——RISC-V
Interview Essentials: what is the mysterious framework asking?
Wu Enda's latest interview! Data centric reasons
Wang Shuang's detailed learning notes of assembly language II: registers
How to earn the first pot of gold in CSDN (we are all creators)
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
随机推荐
《统计学》第八版贾俊平第二章课后习题及答案总结
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Function: calculates the number of uppercase letters in a string
【指针】八进制转换为十进制
线程的实现方式总结
Fundamentals of digital circuit (V) arithmetic operation circuit
内网渗透之内网信息收集(三)
Overview of LNMP architecture and construction of related services
[pointer] find the value of the largest element in the two-dimensional array
数字电路基础(一)数制与码制
Function: find the root of the equation by Newton iterative method
函数:用牛顿迭代法求方程的根
Realize applet payment function with applet cloud development (including source code)
关于超星脚本出现乱码问题
Interview Essentials: what is the mysterious framework asking?
Constants, variables, and operators of SystemVerilog usage
JVM memory model concept
150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
Binary search tree concept