如何转换OpenWeatherMap日期参数(dt_date) [英] How to convert OpenWeatherMap date parameter (dt_date)

查看:58
本文介绍了如何转换OpenWeatherMap日期参数(dt_date)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开放式天气地图API,并且试图弄清楚如何转换默认为"yyyy-mm-dd hh:mm:ss"的日期格式.

I am using the open weather map API and I'm trying to figure out how to convert the date format which is by default "yyyy-mm-dd hh:mm:ss".

我只想显示星期二"之类的日期,而不是冗长的输出.

I would like to simply display the day such as "Tuesday" rather than the long output.

这是我第一次使用API​​,我只是想学习.我已经研究了其他有关如何执行此操作的主题,但是找不到任何资源.也许我只是不知道我应该寻找什么.

This is my first time working with an API and I'm just trying to learn. I have researched other topics on how to do this however I can't find any sources. Maybe I just don't know what exactly I should be looking for.

我的代码现在看起来像这样...

My code right now looks like this...

最终的预测功能是我使用dt_txt输出日期的地方.

The final forecast function is where I am outputting the date with dt_txt.

    function forecastRequest() {

        //MAKE THE AJAX REQUEST

            $.ajax( {
                //DISPLAY WITH ZIPCODE API CALL
                url:'http://api.openweathermap.org/data/2.5/forecast?zip=49009' + ",us&units=imperial" +
                "&APPID=d9347e4e650b022f26f0990856107ac1",
                type: "GET",
                dataType: "jsonp",
                success: function(data){
                    //LOG THE SUCCESS FUNTION TO LET US KNOW IF WE ARE GETTING THE API CALL
                    console.log(data);

                    //SHOW THE DATA RESULTS FROM THE SHOW FUNCTION
                    var widget2 = forecast(data);

                    $("#forecast").html(widget2);


                }
            });
    } // End ajaxRequest Function

}); // End Document.Ready

//DISLAY THE RESULTS
function show(data){
    return   "<h1 class='temp'>" + data.main.temp + "&#176;</h1>" ; 

}

function forecast(data) {
    return   "<p class='temp'>" + data.list[0].main.temp + "&#176; " + data.list[0].dt_txt + "</p>" +
             "<p class='temp'>" + data.list[1].main.temp + "&#176; " + data.list[1].dt_txt + "</p>";
}

推荐答案

没有获取特定日期的特定方法.您可以使用momentjs库并获取日期格式.

There is no specific method to get a day for a particular date. You can use momentjs library for it and can get the date format.

    moment().format('dddd')

这将给您带来美好的一天.

This would give you the day.

这篇关于如何转换OpenWeatherMap日期参数(dt_date)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆