-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalStorage加时间戳.html
More file actions
33 lines (33 loc) · 932 Bytes
/
Copy pathlocalStorage加时间戳.html
File metadata and controls
33 lines (33 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script>
function LocalSTime() {
this.time = ''
this.exitTime = ''
}
LocalSTime.prototype.setItem = (key, value, exitTime) => {
this.exitTime = exitTime;
this.time = new Date().getTime();
var dateCurrent = new Date().getTime()
let obj = {
date: dateCurrent,
key: value
}
let exitdata = JSON.stringify(obj)
if(!window.localStorage.getItem(key)) {
window.localStorage.setItem(key, exitdata);
}
}
LocalSTime.prototype.getItem = (key) => {
let lsData = JSON.parse(localStorage.getItem(key))
let getTime = lsData.date;
let lsValue = lsData.key;
let isExit = new Date().getTime() - getTime <= this.exitTime * 60 * 1000;
if (isExit) {
return window.localStorage.getItem(key)
} else {
window.localStorage.removeItem(key)
}
}
var localS = new LocalSTime()
localS.setItem('clock', 'true', .1)
localS.getItem("clock")
</script>