2012-08-25 4 views
2

asp.net 페이지에서 SimpleWeather jquery 플러그인을 사용하고 있습니다. https://github.com/monkeecreate/jquery.simpleWeatherSimpleWeather jquery plugin

난 그냥이 개 질문이 :

  1. 내가 오전과 오후에 시간을 얻을를, 누군가 24 시간에 그것을 해결하는 방법을 알고 이잖아있다.

  2. 내가 weather.code를 알고 있다면 http://developer.yahoo.com/weather/#codes 나는 어떻게 든 뜨거운, 우박에 대한 나의 자신의 이름을 할 수 있습니까?

    $ .getJSON ( weatherUrl, 기능 (데이터) { 경우 (데이터! == 널 & & data.query.results! == NULL) {$ .each (data.query.results 함수 (I, 결과) { 경우 (.! result.constructor.toString() 같이 IndexOf ("배열") == -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'; 
        } 
    

답변

0

u는 SimpleWeather jQuery 플러그인, 다음 솔루션에서 함께 24 시간 시간을 표시해야하는 경우 유리가 작동하지 않습니다 ...

하지만 여기서 작동하는 솔루션입니다.

js 스크립트에서이 코드를 찾으십시오. 먼저 0을 0X : 내가 XX를 보여 dident 5 : 일몰 후 20시 5분 경우

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

그리고이 해당 코드를 변경 (24H에서 일몰과 함께 몇 가지 문제가 있습니다 그것은 20 시간을 보여 주었다 MM은 시간이 코드는

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

) 그 문제를 해결됩니다 24H 아닌 AM/PM의 예를 보여주는 경우 SunSetTime 및 SunRiseTime을 사용해야합니다. SunSet 및 SunRise.

또한 처음 0 시간에도 문제가있는 경우 HH 시간 문제를 해결합니다. 해피 사용하기 ...

1

플러그인을 조정해야합니다. 맞춤 조건 텍스트를 사용하려면 플러그인을

// 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 제어 할 수 있다면 당신은 마이크로 소프트 아약스 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"); 
       } 
+0

안녕하세요 Thx는 답을 구하는 데 도움이되는 멋진 방법, 2 개의 첫 번째 코드가 있고 작동하는 100 %, 마지막 코드 인 "공백"은 얼마나 많은 일반 JS 코드입니까? 나는 변화가 필요해 !!? plz. 주요 질문에서 편집을 참조하십시오 .. –

+0

UV 인덱스를 얻을 수있는 방법이 있습니다. –

+0

안녕 Yuriy Rozhovetskiy 내 의견을 본 적이있다!? –