Json.stringify () is mostly used in localStorage to set up the local cache and to process data formats when interacting with background data. The cache stores strings regardless of whether they are true or false

Window. The localStorage. SetItem (" dragon ", {name: "wan"}) / / is meant to browser storage key: "dragon", the value: {name: "wan"} Window. The localStorage. The getItem (" dragon ") / / got "[object object]" and we have access to the expected value Window. The localStorage. SetItem (" dragon ", a JSON. Stringify ({name: "wan"})) / / obj first into a JSON string Window. The localStorage. The getItem (" dragon ") / / get "{" name" : "wan"} "= > JSON string JSON. Parse (' {" name" : "wan"} ') / / get the Object {name: "Wan"} JSON string into a JSON object obj form. The parse (' [" asd ", "1111", 32] ') / / to get [" asd ", "1111", 32] parsed into an array of JSON. Parse (' {" name ":" wan "} ', function (key, val) {.......................................... }) // The second argument is a function that can do some data processing with the key-value pair of the first argumentCopy the code

Subtract the distance between the current time, new Date(), and another timestamp

Time of day = 24 hours x60 minutes x60 seconds x1000 milliseconds == 86400000

New Date() => Fri Jul 13 2018 07:54:40 GMT+0800 (utc) new Date().getTime() => 1531439720243 new Date().getFullYear() => 2018 new Date().getMonth() => 6 // getMonth() => 6Copy the code
Thu Jul 12 2018 00:00:00 GMT+0800 new Date('2018-7-12') => Thu Jul 12 2018 00:00:00 GMT+0800 (China Standard Time) 0 o 'clock but: New Date('2018-07-12') => Thu Jul 12 2018 08:00:00 GMT+0800 (Chinese standard time) 8 o 'clock So remember replace(/-/ig,"/")Copy the code
Function getTime(lastTime){// New Date('2018-07-12'); new Date('2018-07-12'); Var s1 = new Date(lasttime.replace (/-/ig,"/")); var s2 = new Date(); runTime = parseInt((s2.getTime() - s1.getTime()) / 1000); Var year = math. floor(runTime / 86400/365); Var runTimeYear = runTime % (86400 * 365); Var month = math.floor (runTimeYear / 86400/30); Var runTimeMonth = runTime % (86400 * 30); Var day = math. floor(runTimeMonth / 86400); var day = math. floor(runTimeMonth / 86400); Var runTimeDay = runTime % 86400; Var hour = math.floor (runTimeDay / 3600); var hour = math.floor (runTimeDay / 3600); Var runTimeHour = runTime % 3600; Var minute = math.floor (runTimeHour / 60); Var runTimeMinute = runTime % 60; Var second = runTimeMinute; / / the number of seconds remaining return year + ', '+ month +', '+ day +', '+ hour +', '+ minute +', '+ second; } var lastTime = "2018-06-20"; console.log(getTime(startTime));Copy the code

conclusion

React QQ group:788023830 —- React/Redux - Old underground hero

Front-end COMMUNICATION QQ group:249620372 —- FRONT - END - JS FRONT END

(Our mission is, for overtime, for baldness… , look up to the big guy), I hope friends to study together