0
votes

My application server is in a different timezone than my browser. I am using Angular date filter to show date in given format. From backend it is coming as 'yyyy-MM-dd' I want it to just show in 'MM-dd-yyyy HH:mm:ss'. But Angular is converting it to local time zone and hence date is changed.

Code:

{{transDateTime | date:'MM-dd-yyyy HH:mm:ss'}} 

Is there any way to stop it to make any timezone conversion and show the date as is.

2

2 Answers

1
votes

Try This

{{getDate(transDateTime)}}

$scope.getDate = function(transDateTime){
    return $filter('date')(transDateTime, 'MM-dd-yyyy HH:mm:ss', timezone);
};

NP: Don't forget to inject $filter in your controller

You can create filter for this

0
votes

You can use ngModelOptions timezone to set the date to UTC time. https://docs.angularjs.org/api/ng/directive/ngModelOptions

EDIT: For displaying only, you should use the timezone in the filter as @Jimbrooism sugested.