The basic idea is that every time somebody visits the website the cookie saves the time and date. If the user then visits the website multiple times the cookie only shows the date and time when the user last visited. At the moment I have the following code which does work put obviously always updates the date and time:
var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
document.cookie ='last_visit='+ dateTime
Edit:For other people who might need help, the following code seems to work:
var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
function getCookieValue(a) {
const b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
}
console.log ("getCookieValue " + getCookieValue("last_visit"));
document.cookie ='last_visit='+ dateTime
You cannot share visited data between users on the cookies without receiving data from the server.
The solution is to save the last visit DateTime into the Database and send it back to the client