# Zeitformat us (PM AM) in 24 Stunden ändern



## stammbowling (22. Mai 2016)

Hallo,

ich benutze ein vorgefertigtes Wetter-Plugin. Auf meiner Webseite http://stammbowling.net werden u.a. die Sonnenaufgangs- und Untergangszeit angezeigt. Das möchte ich in einem 24h Format ausgegeben haben. Der .js- Code lautet:

```
//flatWeatherJqueryPlugin min
//2014-10-21
(function(e,t,n,r){function u(t,n){this.element=t;this.settings=e.extend({},s,n);if(!this.settings.units||this.settings.units=="auto"){this.settings.units=["united states","usa","united states of america","us"].indexOf(this.settings.country.toLowerCase())==-1?"metric":"imperial"}this.settings.forecast=Math.min(this.settings.forecast,5);this._name=i;this.once=false;this.init()}function a(e,t){var n={};if(t.api=="openweathermap"){if(e[0].name!=""){n.location=e[0].name+", "+e[0].sys.country;n.city=e[0].name}else if(e[1].city.name!=""){n.location=e[1].city.name+", "+e[1].city.country;n.city=e[1].city.name}else{n.location=t.location+", "+t.country;n.city=t.location}n.today={};n.today.temp={};n.today.temp.now=Math.round(e[0].main.temp);n.today.temp.min=Math.round(e[0].main.temp_min);n.today.temp.max=Math.round(e[0].main.temp_max);n.today.desc=e[0].weather[0].description.capitalize();n.today.code=e[0].weather[0].id;n.today.wind=e[0].wind;n.today.humidity=e[0].main.humidity;n.today.pressure=e[0].main.pressure;n.today.sunrise=l(e[0].sys.sunrise);n.today.sunset=l(e[0].sys.sunset);n.today.day=f(new Date);n.forecast=[];for(var r=0;r<t.forecast;r++){var i={};i.day=f(new Date(e[1].list[r].dt*1e3));i.code=e[1].list[r].weather[0].id;i.desc=e[1].list[r].weather[0].description.capitalize();i.temp={max:Math.round(e[1].list[r].temp.max),min:Math.round(e[1].list[r].temp.min)};n.forecast.push(i)}}else if(t.api=="yahoo"){var s={0:"900",1:"901",2:"902",3:"212",4:"200",5:"616",6:"612",7:"611",8:"511",9:"301",10:"511",11:"521",12:"521",13:"600",14:"615",15:"601",16:"601",17:"906",18:"611",19:"761",20:"741",21:"721",22:"711",23:"956",24:"954",25:"903",26:"802",27:"802",28:"802",29:"802",30:"802",31:"800",32:"800",33:"951",34:"951",35:"906",36:"904",37:"210",38:"210",39:"210",40:"521",41:"602",42:"621",43:"602",44:"802",45:"201",46:"621",47:"210",3200:"951"};e=e.query.results.channel;n.location=e.location.city+", "+e.location.country;n.city=e.location.city;n.today={};n.today.temp={};n.today.temp.now=Math.round(e.item.condition.temp);n.today.temp.min=Math.round(e.item.forecast[0].low);n.today.temp.max=Math.round(e.item.forecast[0].high);n.today.desc=e.item.condition.text.capitalize();n.today.code=s[e.item.condition.code];n.today.wind={};n.today.wind.speed=e.wind.speed;n.today.wind.deg=e.wind.direction;n.today.humidity=e.atmosphere.humidity;n.today.pressure=e.atmosphere.pressure;n.today.sunrise=e.astronomy.sunrise.toUpperCase();n.today.sunset=e.astronomy.sunset.toUpperCase();n.today.day=f(new Date);n.forecast=[];for(var r=0;r<t.forecast;r++){var i={};i.day=f(new Date(e.item.forecast[r].date));i.code=s[e.item.forecast[r].code];i.desc=e.item.forecast[r].text.capitalize();i.temp={max:Math.round(e.item.forecast[r].high),min:Math.round(e.item.forecast[r].low)};n.forecast.push(i)}}return n}function f(e){return["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"][e.getDay()]}function l(e){e=new Date(e*1e3);var t=e.getHours();var n=e.getMinutes();var r=t>=12?"PM":"AM";t=t%12;t=t?t:12;n=n<10?"0"+n:n;var i=t+":"+n+" "+r;return i}function c(e,t,n){var r=t;if(r>=0&&r<=11.25||r>348.75&&r<=360){r="N"}else if(r>11.25&&r<=33.75){r="NNO"}else if(r>33.75&&r<=56.25){r="NO"}else if(r>56.25&&r<=78.75){r="ONO"}else if(r>78.75&&r<=101.25){r="O"}else if(r>101.25&&r<=123.75){r="OSO"}else if(r>123.75&&r<=146.25){r="SO"}else if(r>146.25&&r<=168.75){r="SSO"}else if(r>168.75&&r<=191.25){r="S"}else if(r>191.25&&r<=213.75){r="SSW"}else if(r>213.75&&r<=236.25){r="SW"}else if(r>236.25&&r<=258.75){r="WSW"}else if(r>258.75&&r<=281.25){r="W"}else if(r>281.25&&r<=303.75){r="WNW"}else if(r>303.75&&r<=326.25){r="NW"}else if(r>326.25&&r<=348.75){r="NNW"}var i=n=="metric"?"km/h":"mph";return r+" "+e+" "+i}var i="flatWeatherPlugin";var s={location:"Waterloo, ON",country:"Germany",displayCityNameOnly:false,api:"openweathermap",forecast:5,apikey:"",view:"full",render:true,loadingAnimation:true};var o={openweathermap:["http://api.openweathermap.org/data/2.5/weather","http://api.openweathermap.org/data/2.5/forecast/daily"],yahoo:["https://query.yahooapis.com/v1/public/yql"]};e.extend(u.prototype,{init:function(){if(this.settings.render){if(this.settings.loadingAnimation&&!this.once){this.loading=e("<div/>",{id:"flatWeatherLoading","class":"wi loading"});this.loading.appendTo(this.element)}this.fetchWeather().then(this.render,this.error)}this.once=true},fetchWeather:function(){var t=this;var n=new e.Deferred;var r=[];var i=this.settings.location+" "+this.settings.country;if(this.settings.api=="openweathermap"){var s={};s.q=i;s.units=this.settings.units;if(this.settings.apikey)s.appid=this.settings.apikey;r.push(s);s.cnt=this.settings.forecast+1;r.push(s)}else if(this.settings.api=="yahoo"){var u=this.settings.units=="metric"?"c":"f";var s={};s.q="select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='"+i+"') AND u='"+u+"'";s.env="store://datatables.org/alltableswithkeys";s.format="json";r.push(s)}var f=[];for(var l=0;l<o[this.settings.api].length;l++){f.push(e.get(o[this.settings.api][l],r[l]))}e.when.apply(this,f).done(function(){var r=Array.prototype.slice.call(arguments);if(f.length>1){r=r.map(function(e){return e[0]})}else{r=r[0]}if(t.settings.api=="openweathermap"&&!(r[0].cod=="200"&&r[1].cod=="200")){console.log("Error interacting with the openweathermap api see error object below for details:");console.log(r);n.reject(r,t)}else if(t.settings.api=="yahoo"&&(r.query.count==0||r.query.results.channel.description=="Yahoo! Weather Error")){console.log("Error interacting with the yahoo api see error object below for details:");console.log(r);n.reject(r,t)}else{var i=a(r,t.settings);t._weather=i;e.data(t.element,"weather",i);n.resolve(i,t)}}).fail(function(e){console.log("fail");n.reject(e,t)});return n},error:function(t,n){if(!n){n=this}if(n.settings.loadingAnimation&&n.settings.render){n.loading.remove()}if(n.settings.api=="openweathermap"){if(t[0].cod!="200"){t=t[0].cod+" "+t[0].message+". See console log for details."}else{t=t[1]+" See console log for details."}}else if(n.settings.api=="yahoo"){if(t.query.results){t="Error: "+t.query.results.channel.item.title+". See console log for details."}else{t="Error: no results. See console log for details."}}var r=e("<div/>",{"class":"flatWeatherPlugin "+n.settings.view});e("<h2/>").text("Error").appendTo(r);e("<p/>").text(t).appendTo(r);e(n.element).html(r);return e(n.element)},render:function(t,n){if(!n){n=this;t=this._weather}var r=n.settings.units=="metric"?"&#176;C":"&#176;F";if(n.settings.loadingAnimation&&n.settings.render){n.loading.remove()}var i=e("<div/>",{"class":"flatWeatherPlugin "+n.settings.view});if(n.settings.displayCityNameOnly){e("<h2/>").text(t.city).appendTo(i)}else{e("<h2/>").text(t.location).appendTo(i)}if(n.settings.view!="forecast"){var s=e("<div/>",{"class":"wiToday"});var o=e("<div/>",{"class":"wiIconGroup"});e("<div/>",{"class":"wi "+"wi"+t.today.code}).appendTo(o);e("<p/>",{"class":"wiText"}).text(t.today.desc).appendTo(o);o.appendTo(s);e("<p/>",{"class":"wiTemperature"}).html(t.today.temp.now+"<sup>"+r+"</sup>").appendTo(s);s.appendTo(i)}if(n.settings.view!="simple"){var u=e("<div/>",{"class":"wiDetail"});if(n.settings.view=="partial"){e("<p/>",{"class":"wiDay"}).text(t.today.day).appendTo(s)}if(n.settings.view!="partial"){if(n.settings.view!="today"){e("<p/>",{"class":"wiDay"}).text(t.today.day).appendTo(u)}var a=e("<ul/>",{"class":"astronomy"}).appendTo(u);e("<li/>",{"class":"wi sunrise"}).text(t.today.sunrise).appendTo(a);e("<li/>",{"class":"wi sunset"}).text(t.today.sunset).appendTo(a);var f=e("<ul/>",{"class":"temp"}).appendTo(u);e("<li/>").html("Max. Grad : "+t.today.temp.max+"<sup>"+r+"</sup>").appendTo(f);e("<li/>").html("Min. Grad : "+t.today.temp.min+"<sup>"+r+"</sup>").appendTo(f);var l=e("<ul/>",{"class":"atmosphere"}).appendTo(u);e("<li/>",{"class":"wi humidity"}).text(t.today.humidity).appendTo(l);e("<li/>",{"class":"wi pressure"}).text(t.today.pressure).appendTo(l);e("<li/>",{"class":"wi wind"}).text(c(t.today.wind.speed,t.today.wind.deg,n.settings.units)).appendTo(l);u.appendTo(s)}if(n.settings.view!="today"||n.settings.view=="forecast"){var h=e("<ul/>",{"class":"wiForecasts"});var p=n.settings.view=="forecast"?0:1;for(var d=p;d<t.forecast.length;d++){var v=e("<li/>",{"class":"wiDay"}).html("<span>"+t.forecast[d].day+"</span>").appendTo(h);var m=e("<ul/>",{"class":"wiForecast"}).appendTo(v);e("<li/>",{"class":"wi "+"wi"+t.forecast[d].code}).appendTo(m);e("<li/>",{"class":"wiMax"}).html(t.forecast[d].temp.max+"<sup>"+r+"</sup>").appendTo(m);e("<li/>",{"class":"wiMin"}).html(t.forecast[d].temp.min+"<sup>"+r+"</sup>").appendTo(m)}h.appendTo(i)}}e(n.element).html(i);return e(n.element)}});e.fn[i]=function(t,n){if(e.isFunction(u.prototype[t])){return this.data("plugin_"+i)[t](n)}return this.each(function(){if(!e.data(this,"plugin_"+i)){var n=new u(this,t);return e.data(this,"plugin_"+i,n)}})};String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1)};})(jQuery,window,document)
```

Ich habe mich schon hier dran versucht: 
	
	
	
	





```
var r=t>=12?"PM":"AM";t=t%12;t=t?t:12
```
, aber bin leider nicht weiter gekommen.

Hat jemand einen Tipp für mich?


----------



## stg (22. Mai 2016)

Der erste Tipp wäre, dass du es in einem JavaScript-Forum probierst; hier geht es um Java!
Der zweite Tipp: Wenn du Code postest, dann formatiere den doch bitte auch so, dass man ihn lesen kann...


----------



## thet1983 (22. Mai 2016)

Hab zwar mit js nichts an Hut aber ich wenn ich Google frage würde da vorbei schauen 
http://www.webdeveloper.com/forum/forumdisplay.php?3-JavaScript


----------



## stammbowling (22. Mai 2016)

Ok, das war mir so nicht bewusst! Danke trotzdem.


----------

