2

I am getting the date string from server in the following format:

$scope.dateform = {
   "dob": "22-06-1980"
} 

But i want to convert into GMT form using angularjs inside controller.

Sat Jun 22 1980 00:12:00 GMT+0530

Is there any way to convert?

vishnu
  • 4,377
  • 15
  • 52
  • 89
  • Possible duplicate of [Changing Date Time Format using jquery/javascript](http://stackoverflow.com/questions/23946698/changing-date-time-format-using-jquery-javascript) – Durgpal Singh Dec 18 '15 at 07:25

4 Answers4

4

This is fairly simple to do in angular you use the build in date feature.

In your controller store the date in a variable

$scope.dateVariable = my-non-human-date-string

In your view simply output it inside handle bars with angular's date filter attached to it.

{{dateVariable | date : "dd/MM/yy HH:mm:ss"}}

You can also find different formats for dates at the following link.

https://docs.angularjs.org/api/ng/filter/date

Evan Burbidge
  • 827
  • 9
  • 16
2

Its really simple if you use moment.js

what you have to do is

$scope.dateform = {
   "dob": "22-06-1980"
} 
var momentObj = moment($scope.dateform.dob, 'DD-MM-YYYY');

console.log(momentObj .toString()); // here you will the the format you need

here i have create a demo for you.

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92
0

You can use momentjs

moment("25-12-1995", "DD-MM-YYYY");
Olga Akhmetova
  • 490
  • 1
  • 6
  • 19
0

Simply use date filter in html code in angularjs.

Like this

date:'dd/MM/yyyy'
Keshava GN
  • 4,195
  • 2
  • 36
  • 47