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