JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<button class="update-1">Перезаписать data1</button>
<button class="update-2">Перезаписать data2</button>
CSS
button {
cursor: pointer;
}
JavaScript
function getTimeFunc() {
var actualTime = new Date();
if(actualTime.getSeconds() < 10) {
var seconds = '0' + actualTime.getSeconds();
} else {
var seconds = actualTime.getSeconds();
}
if(actualTime.getMinutes() < 10) {
var minutes = '0' + actualTime.getMinutes();
} else {
var minutes = actualTime.getMinutes();
}
if(actualTime.getHours() >= 10 && actualTime.getHours() <= 23) {
var hours = actualTime.getHours();
} else {
var hours = '0' + actualTime.getHours();
}
if(actualTime.getDate() < 10) {
var currentDate = '0' + actualTime.getDate();
} else {
var currentDate = actualTime.getDate();
}
if(actualTime.getMonth() + 1 < 10) {
var currenMonth = '0' + (actualTime.getMonth() + 1);
} else {
var currenMonth = actualTime.getMonth() + 1;
}
var currentYear = actualTime.getFullYear();
var currentTime = hours + ':' + minutes + ':' + seconds;
return {
time: currentTime+', '+ currentDate + '.' + currenMonth + '.' + currentYear
}
}
function writeLS1() {
var time = getTimeFunc().time;
localStorage.someData1 = 123 + '; time ' + time;
}
function writeLS2() {
var time = getTimeFunc().time;
localStorage.someData2 = 123 + '; time ' + time;
}
writeLS2();
function getLSdata() {
var data1 = localStorage.someData1;
var data2 = localStorage.someData2;
var position1 = data1.indexOf('time');
var position2 = data2.indexOf('time');
var time1 = data1.substring(position1+5, 30);
var time2 = data2.substring(position2+5, 30);
var hours1 = parseInt(time1.substring(0,2));
var minutes1 = parseInt(time1.substring(3,5));
var seconds1 = parseInt(time1.substring(6,8));
var date1 = parseInt(time1.substring(10,12));
var month1 = parseInt(time1.substring(13,15));
var year1 = parseInt(time1.substring(16,20));
var hours2 =...