【发布时间】:2015-03-10 20:56:10
【问题描述】:
-
将值设置到本地存储中:
$scope.SetLocalStorage('My-' + $rootScope.UserId, moment()); -
从本地存储中获取值:
var dt = moment($scope.GetLocalStorage('My-' + $rootScope.UserId)); -
从本地存储中获取日期时间:
var dTime = moment(dt);
这里显示无效日期:
我需要小时的时差:
var timeDifference = moment().diff(moment(dTime)), 'hours');
问题:'timeDifference' 总是给出 Nan。
你能告诉我为什么吗?任何帮助将不胜感激。
我使用过的库:Local-storage 和 moment.js
【问题讨论】:
-
我猜,$scope.GetLocalStorage('My-' + $rootScope.UserId) 是你的 moment() 是当前时间,为什么你有 moment('current time'),然后又时刻(momet('当前时间'))?
-
@Nielarshi 我需要将当前日期时间存储到本地存储和以后的时间我现在需要在哪里检查存储值和日期时间的差异?
-
我认为“'My-' + $rootScope.UserId”(用于存储在本地存储中的密钥)有问题。我没有看到你正在做的任何错误。通过给出一些字符串键来检查,而不是从 rootScope 获取。
-
var dTime = moment(dt); // 不是必需的,var timeDifference = moment().diff(moment(dTime)), 'hours'); // 这也不是必需的。只要你做 var timeDifference = moment().diff(dt), 'hours');
标签: javascript angularjs local-storage momentjs