Solve the 8-hour problem of MongoDB isodate

Source: Internet
Author: User
Tags local time

The server uses mongoose to manipulate MongoDB, where the Date field in the schema is defined as follows:

Date:   {type:date, default:date.now},//operation date

INSERT INTO MongoDB adte: "Date": Isodate ("2015-08-15t03:26:36.086z"),

8 hours difference from the current time, the client uses angular to operate, the content displayed on the page is: 2015-08-15t03:26:36.086z

Processing is now done by using Moment.js on the client, by defining a filter for processing.

(1) Installation Moment.js

[Email protected]:app01$ Bower Install--save moment

(2) Define Filter

Angular.module (' Angularfullstacktestapp '). Controller (' Advicectrl ',function($scope, $http, socket) {$scope. advicelist= []; /** * Get feedback list*/$scope. Getadvicelist=function() {$http. Get ('/api/advices '). Success (function(Result) {$scope. advicelist=result; }). Error (function() {alert ("Network Error");    });    };    $scope. Getadvicelist (); $scope. $on (' $destroy ',function() {socket.unsyncupdates (' Thing ');  }); }). Filter (' Getlocaltimefilter ',function(){//convert isodate to local time using Moment.js    return function(input) {if(Input && input.length>11){        returnMoment (Input). Format (' Yyyy-mm-dd HH:mm:ss '); }      returninput;  }; });

(3) using filter

TD (Style= "Vertical-align:middle") {{a.date | getlocaltimefilter}}

The operating interface time appears normal: 2015-08-15 11:26:36



Solve the 8-hour problem of MongoDB isodate

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.