2

asp.netページでSimpleWeather jqueryプラグインを使用していますが、正常に動作しています。 https://github.com/monkeecreate/jquery.simpleWeather

2 つの質問があります。

  1. AM と PM の時刻を取得します。24 時間に修正する方法を知っている人はいますか。

  2. もし私がweather.code http://developer.yahoo.com/weather/#codesを知っていれば、どうにかして暑い、雹などの私自身の名前を使用できますか?

    $.getJSON( weatherUrl, function (data) { if (data !== null && data.query.results !== null) { $.each(data.query.results, function (i, result) { if (result .constructor.toString().indexOf("Array") !== -1) { 結果 = 結果[0]; }

        var currentDate = new Date();
        var sunRise = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunrise);
        var sunSet = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunset);
    
        if (currentDate > sunRise && currentDate < sunSet) {
            var timeOfDay = 'd';
        } else {
            var timeOfDay = 'n';
        }
    
4

2 に答える 2

1

プラグインを微調整する必要があります。カスタム条件テキストを有効にするには、新しい options プロパティを追加して条件コードをカスタム テキストにマップし、以下のようにプラグインで使用することができます。

// this code is a part of weater object initialization
currently: options.conditions && options.conditions[result.item.condition.code] ? options.conditions[result.item.condition.code] : result.item.condition.text,
high: result.item.forecast[0].high,
low: result.item.forecast[0].low,
forecast: options.conditions && options.conditions[result.item.forecast[0].code] ? options.conditions[result.item.forecast[0].code] : result.item.forecast[0].text,

カスタムプロパティをプラグインに渡します:

$.simpleWeather({
    location: 'Copenhagen, Denmark',
    unit: 'c',
    conditions: { 26: 'Overskyet', 27: 'Mest skyet', 28: 'Mest skyet', 36: 'Hagl' },

日の出と日の入りの時間形式を変更するには、プラグインを微調整することもできます。今回は時間を形式で解析し、代わりh:mm ttに形式で表示する必要があります。HH:mmページを制御できる場合ScriptManagerは、Microsoft Ajax Date オブジェクト拡張関数を使用できます。

プラグインのコードを変更しました:

$.getJSON(
    weatherUrl,
    function (data) {
        if (data !== null && data.query.results !== null) {
            $.each(data.query.results, function (i, result) {
                if (result.constructor.toString().indexOf("Array") !== -1) {
                    result = result[0];
                }

                var currentDate = new Date();
                if (Date.parseInvariant) {
                    result.astronomy.sunrise = Date.parseInvariant(result.astronomy.sunrise, "h:mm tt").format("HH:mm");
                    result.astronomy.sunset = Date.parseInvariant(result.astronomy.sunset, "h:mm tt").format("HH:mm");
                }
于 2012-08-25T13:12:02.890 に答える
0

SimpleWeather jQuery プラグインで 24 時間表示する必要がある場合、Yuriy のソリューションは機能しません...

しかし、ここに実用的な解決策があります。

js スクリプトでこのコードを見つけます。

var currentDate = new Date();
var sunRise = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunrise);
var sunSet = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunset);

if (currentDate > sunRise && currentDate < sunSet) {
    var timeOfDay = 'd';
} else {
    var timeOfDay = 'n';
}

そして、そのコードをこれに変更します (日没が 20:05 の場合、24 時間の日没に問題があり、時刻が 20:5 として表示されました。MM 時間で xx:0x の最初の 0 を表示しませんでした。その問題を修正しています)

                        var currentDate = new Date();
                        var sunRise = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunrise);
                        var sunSet = new Date(currentDate.toDateString() + ' ' + result.astronomy.sunset);

                        var sunRiseHour = "" + sunRise.getHours() + "";
                        var sunRiseMinute = "" + sunRise.getMinutes() + "";
                        var sunSetHour = "" + sunSet.getHours() + "";
                        var sunSetMinute = "" + sunSet.getMinutes() + "";

                        if (sunRiseHour.length == 1) {
                            sunRiseHour = "0" + sunRiseHour;
                        }
                        if (sunRiseMinute.length == 1) {
                            sunRiseMinute = "0" + sunRiseMinute;
                        }
                        if (sunSetHour.length == 1) {
                            sunSetHour = "0" + sunSetHour;
                        }
                        if (sunSetMinute.length == 1) {
                            sunSetMinute = "0" + sunSetMinute;
                        }
                        var sunRiseTime = sunRiseHour + ":" + sunRiseMinute;
                        var sunSetTime = sunSetHour + ":" + sunSetMinute;


                        if (currentDate > sunRise && currentDate < sunSet) {
                            var timeOfDay = 'd';
                        } else {
                            var timeOfDay = 'n';
                        }

AM/PM ex ではなく 24H を表示する場合は、SunSetTime と SunRiseTime を使用することを忘れないでください。サンセットとサンライズ。

また、最初の 0 時間にも問題がある場合は、HH 時間の問題も修正されます。使って幸せ...

于 2012-09-09T10:22:03.567 に答える