📜  在 chrome 存储扩展中存储当前日期 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:55.132000             🧑  作者: Mango

代码示例1
// Setting side
const currentTime = (new Date()).toJSON();
const items = { 'testdate': currentTime }; 
chrome.storage.local.set(items, () => {
    if (chrome.runtime.lastError) {
        console.error(chrome.runtime.lastError.message);
    }
});


//Getting side
chrome.storage.local.get(['testdate'], (result) => {
    if (chrome.runtime.lastError) {
        console.error(chrome.runtime.lastError.message);
    } else {
        const storedJSONDate = result['testdate'];
        const testdate = new Date(storedJSONDate);
        console.log(testdate);
    }
});