我在模态中使用angular-material-datetimepicker来输入日期和时间。但是,angular会在json中发送所有数据服务器端,并将时间更改为UTC。在重新加载我的客户端时,显示我不想要的UTC时间。如何让客户端显示当地时间(在我的情况下为GMT +2)?如何仅操作json字符串的日期部分?我在其他类似的SO q和论坛上看到过令人困惑的解决方案。谢谢。
关于模态html
<div class="time">
<md-input-container class="md-input-has-placeholder start_time">
<label>Start Date/Time</label>
<input mdc-datetime-picker="" date="true" time="true" type="text" id="datetime" placeholder="Start" min-date="date" format="DD/MM/YYYY hh:mm" ng-model="Project.StartAt" class=" md-input">
</md-input-container>
<md-input-container class="md-input-has-placeholder endtime">
<label>End Date/Time</label>
<input mdc-datetime-picker="" date="true" time="true" type="text" id="datetime" placeholder="End" min-date="date" format="DD/MM/YYYY hh:mm" ng-model="Project.EndAt" class=" md-input">
</md-input-container>
</div>
角
$scope.editProject = function(data) {
$scope.showSelected = true;
$scope.SelectedProject = data;
var fromDate = moment(data.start).format('DD/MM/YYYY LT');
var endDate = moment(data.end).format('DD/MM/YYYY LT');
$scope.Project = {
ProjectID : data.projectID,
Client : data.client,
Title : data.title,
Description: data.description,
Employees: data.employees,
StartAt : fromDate,
EndAt : endDate,
IsFullDay : false
}
$scope.ShowModal()
},
$scope.ShowModal = function(){
$scope.option = {
templateUrl: 'modalContent.html',
controller: 'modalController',
controllerAs: '$ctrl',
backdrop: 'static',
resolve: {
Project : function () {
return $scope.Project;
},
SelectedProject : function () {
return $scope.SelectedProject;
},
projects: function () {
return $ctrl.projects;
}
}
};
var modal = $uibModal.open($scope.option);
modal.result.then(function (data) {
$scope.Project = data.project;
switch (data.operation){
case 'Save':
//Save here
$http({
method: 'POST',
url: '/',
data: $scope.Project
}).then(function(response){
if(response.data.status){
$scope.projects.push(Project);
}
})
break;
答案 0 :(得分:2)
您可以为此应用过滤器:
$scope.yourDate= $filter('date')(new Date($scope.yourDate), 'yyyy-MM-dd'); // Try different format as per your requirement
不要忘记注入依赖$ filter。