Ask a js to judge whether the time is longer than the current 3 hours.

above is the time when the request arrives. If you judge whether this time is more than 3 hours compared with the current time

=
this question is very weak. Since
has caused so much discussion,
has the value of the problem.
why step on it.

Mar.05,2021

Date.now()-new Date(create_time)>3*60*60*1000

1. Cannot use the local time of the front end to judge! Cannot use the local time of the front end to judge! Cannot use the local time of the front end to judge!

2. The timestamp generated by the backend for another interface (the current time of the system) is required, and then all are converted to timestamp . The specific prompts are as follows:

let ctime =  'create_time' 
let 3hours = `60 * 60 * 3 * 1000` //
let time = ''  + 3hours //
if(ctime>time) console.log('');

in fact, the real essence of this problem is that it cannot be judged by local time. You can see some of the previous answers, including I thought Date.now () would be fine at that time, but this is not right, so it can be seen that this question is still valuable, although it is not the value raised by this question


convert the local timestamp minus 3 hours into Greenwich mean time and then compare it with


time stamp

let serverDate = new Date(rawTime.replace(new RegExp(/-/gm), '/'))
let nowDate = new Date()
let myTime = nowDate.getTime() - serverDate.getTime()
if (myTime > 10800000) {
    // do something
}

function isThreeHourAgo(time) {
  const now = Date.now()
  const d = new Date(time)
  const secDiff = (now - d) / 1000
  return secDiff > 3 * 60 * 60
}

for more detailed features, take a look at the moment library.
various time-related processes. Look at the file.


let date = new Date(); //now
date.setTime(date.getTime() + 3 * 3600 * 1000); //3hour later

it is best to use monent.js

for complex time operations.

time is converted to timestamp to calculate


check time on the front end. I'm afraid it's not correct. For example, if you change the time of your mobile phone, it will be wrong

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e78f-2c410.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e78f-2c410.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?