store current date in chrome storage extension

Solutions on MaxInterview for store current date in chrome storage extension by the best coders in the world

showing results for - "store current date in chrome storage extension"
Carsen
22 Oct 2018
1
2// Setting side
3const currentTime = (new Date()).toJSON();
4const items = { 'testdate': currentTime }; 
5chrome.storage.local.set(items, () => {
6    if (chrome.runtime.lastError) {
7        console.error(chrome.runtime.lastError.message);
8    }
9});
10
11
12//Getting side
13chrome.storage.local.get(['testdate'], (result) => {
14    if (chrome.runtime.lastError) {
15        console.error(chrome.runtime.lastError.message);
16    } else {
17        const storedJSONDate = result['testdate'];
18        const testdate = new Date(storedJSONDate);
19        console.log(testdate);
20    }
21});
22