0

This is my route through which I am making a ajax request for weather api,and in return getting a json response.In the json response there is a key 'dt' which is in unix format. So I want to get the day by converting this unix date and display it on my template.Please help.... Thanks in advance.

App.WeatherRoute = Ember.Route.extend({
model: function() {  

    var weather=[]
    Ember.$.ajax({
        async:false,
        url:"http://api.openweathermap.org/data/2.5/forecast/daily?q=Pune&mode=json&units=metric&cnt=7",
        success:function(data){
                                weather.push(data.list);                                        
                                }
                })
    return weather;
    }
});
Athafoud
  • 2,898
  • 3
  • 40
  • 58
  • Take a look into [this](http://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript) and this for the rest of the supported methods [this one](http://www.w3schools.com/jsref/jsref_obj_date.asp) since you want the day – Athafoud Jun 24 '14 at 07:20
  • http://momentjs.com/ can be used it in a handlebars helper to convert the date/time to what you want. As seen here https://github.com/kiwiupover/ember-weather/blob/master/app/helpers/date-formatter.js – kiwiupover Jun 24 '14 at 07:26

1 Answers1

0

Try something like this:

App.WeatherRoute = Ember.Route.extend({
model: function () {

    var weather = []
    Ember.$.ajax({
        async: false,
        url: "http://api.openweathermap.org/data/2.5/forecast/daily?q=Pune&mode=json&units=metric&cnt=7",
        success: function (data) {

            data.list.map(function (elem) {
                dt = new Date(elem.dt * 1000);
                elem.dt = dt;
                weather.push(elem);
            });
        }
    })
    return weather;
  }
});
CuriousMind
  • 33,537
  • 28
  • 98
  • 137