1

我了解当前日期和时间是从new Date.getTime()

如何实现它,以便所有用户的每个新帖子都将被标记日期和时间并与帖子内容一起保存?

var timestamp = new Date.getTime()还是$scope.timestamp = new Date.getTime()?使用 ng-click=submitPost() 提交表单时,如何在数组中保存日期?

我插入以下内容以用日期和时间标记每个条目。在提交后控制器中:

$scope.post = {url: 'http://', title: '', timestamp: new Date()};

并在 html

{{post.timestamp}}


对条目的时间戳注释更新:

$scope.addComment = function () {
        var comment = {
            text: $scope.commentText,
            creator: $scope.user.profile.username,
            creatorUID: $scope.user.uid,
            timestamp: new Date().toUTCString() //I added it here but doesnt work
        };
        $scope.comments.$add(comment);
        $scope.commentText = '';
    };
4

1 回答 1

0

分配日期的最佳方法是使用 toISOString

 $scope.post = {url: 'http://', title: '', timestamp: new Date().toISOString()};

使用 ISO 格式可以避免所有环境/浏览器特定的问题。

于 2014-10-26T15:36:23.137 回答