简体   繁体   English

如何转换从余烬路线的模型钩返回的unix日期,以便可以在我的模板中将其显示为一天

[英]How to convert unix date returning from model hook of ember route,so that it can be displayed as a day in my template

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. 这是我向天气api发出ajax请求的路线,作为回报,我得到了json响应。在json响应中,存在一个Unix格式的键“ dt”。 So I want to get the day by converting this unix date and display it on my template.Please help.... Thanks in advance. 因此,我想通过转换此unix日期并将其显示在我的模板上来获得一天。请帮助...。在此先感谢。

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;
    }
});

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;
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM