zoukankan      html  css  js  c++  java
  • 解决mongodb ISODate相差8小时问题

    服务端使用mongoose操作mongodb,其中Schema中的日期字段定义如下:

    date:   {type:Date, default:Date.now},//操作日期

    插入到mongodb中adte为:"date" : ISODate("2015-08-15T03:26:36.086Z"),

    与当前时间相差8小时,客户端采用angular进行操作,在页面上展示的内容为:2015-08-15T03:26:36.086Z

    现在通过使用moment.js在客户端进行处理,处理方式是定义一个过滤器filter来进行处理.

    (1)安装moment.js

    y@y:app01$ bower install --save moment

    (2)定义filter

    angular.module('angularFullstackTestApp')
      .controller('AdviceCtrl', function ($scope,$http,socket) {
    
        $scope.adviceList = [];
    
        /**
         * 获取意见反馈列表
         */
        $scope.getAdviceList = function(){
          $http.get('/api/advices').success(function(result) {
            $scope.adviceList = result;
          }).error(function(){
            alert("网络错误");
          });
        };
    
        $scope.getAdviceList();
    
        $scope.$on('$destroy', function () {
          socket.unsyncUpdates('thing');
        });
      }).filter('getLocalTimeFilter',function(){//使用moment.js将ISODate转换为本地时间
        return function(input){
          if(input && input.length>11){
            return moment(input).format('YYYY-MM-DD HH:mm:ss');
          }
          return input;
        };
      });

    (3)使用filter

    td(style="vertical-align:middle") {{a.date | getLocalTimeFilter}}

    此时操作界面时间显示正常:2015-08-15 11:26:36



  • 相关阅读:
    linux开启oracle服务
    一个tomcat多域名绑定多项目
    linux安装jdk1.7.0
    windows 查看端口进程和杀死进程
    windows2008 扩大远程连接数
    windows下用bak文件备份数据库
    linux常用命令
    mysql 开启远程连接访问
    windows 下tomcat安装
    IBM公司面试题
  • 原文地址:https://www.cnblogs.com/yshyee/p/4732341.html
Copyright © 2011-2022 走看看