XWidgetSoft Forum https://www.bbs.xwidget.com/ |
|
sunrise, sunset, moonrise, and moonset in 12 hr time https://www.bbs.xwidget.com/viewtopic.php?f=3&t=4279 |
Page 1 of 1 |
Author: | ELY_M [ March 24th, 2014, 1:15 am ] |
Post subject: | sunrise, sunset, moonrise, and moonset in 12 hr time |
I noticed that the sun and moon rises and sets are in 24 hr format. how can you set those times to be in 12 hr? |
Author: | Jimking [ March 24th, 2014, 1:43 am ] |
Post subject: | Re: sunrise, sunset, moonrise, and moonset in 12 hr time |
I wanted to but I'm afraid that we have to wait for the next version of XWidget. I hope that the Dev will add new tags for this.. Like the 12h for the weather's update time.. |
Author: | hamid [ March 27th, 2014, 3:35 pm ] |
Post subject: | Re: sunrise, sunset, moonrise, and moonset in 12 hr time |
ELY_M wrote: I noticed that the sun and moon rises and sets are in 24 hr format. how can you set those times to be in 12 hr? if you familiar with scripting you can do this with a little scripting: just you need to split hh:mm by ":" to get the hour from it and change the hour to 12hour and recreate the hh:mm format: example: //need to create text1 Object //need to have accweathercore1 in widget //don't forget to add [datetimecore1OnUpdate] in the [OnUpdate] Section of datetimecore1 in designer Code: function datetimecore1OnUpdate(Sender)
{ tmp1=accweathercore1.get("%sunSet").split(":") if(tmp1[0]>12) { tmp1[0]=tmp1[0]-12 text1.Text=tmp1[0]+":"+tmp1[1]+" PM" } else if(tmp1[0]==0) { text1.Text=12+":"+tmp1[1]+" AM" } else if(tmp1[0]==12) { text1.Text=12+":"+tmp1[1]+" PM" } else if(tmp1[0]<12) { text1.Text=tmp1[0]+":"+tmp1[1]+" AM" } } |
Author: | Jimking [ March 27th, 2014, 4:09 pm ] |
Post subject: | Re: sunrise, sunset, moonrise, and moonset in 12 hr time |
Good hamid! ![]() I continue to believe though that if Tony add a tag for this on the next version, will be more simple for all. ![]() |
Author: | ELY_M [ April 3rd, 2014, 3:52 pm ] |
Post subject: | Re: sunrise, sunset, moonrise, and moonset in 12 hr time |
I did scripting. I had to modify to strip the 0 from the sunrise Code: function datetimecore1OnUpdate(Sender)
{ //sunrise tmp1=accweathercore1.get("%sunRise").split(":") if(tmp1[0]>12) { tmp1[0]=tmp1[0]-12 sunrise.Text="Sunrise: "+tmp1[0]+":"+tmp1[1]+" PM" } else if(tmp1[0]==0) { sunrise.Text="Sunrise: "+12+":"+tmp1[1]+" AM" } else if(tmp1[0]==12) { sunrise.Text="Sunrise: "+12+":"+tmp1[1]+" PM" } else if(tmp1[0]<12) { if (amhour=tmp1[0].split("0")) sunrise.Text="Sunrise: "+amhour[1]+":"+tmp1[1]+" AM" else sunrise.Text="Sunrise: "+tmp1[0]+":"+tmp1[1]+" AM" } //sunset tmp1=accweathercore1.get("%sunSet").split(":") if(tmp1[0]>12) { tmp1[0]=tmp1[0]-12 sunset.Text="Sunset: "+tmp1[0]+":"+tmp1[1]+" PM" } else if(tmp1[0]==0) { sunset.Text="Sunset: "+12+":"+tmp1[1]+" AM" } else if(tmp1[0]==12) { sunset.Text="Sunset: "+12+":"+tmp1[1]+" PM" } else if(tmp1[0]<12) { sunset.Text="Sunset: "+tmp1[0]+":"+tmp1[1]+" AM" } } |
Author: | hamid [ April 3rd, 2014, 4:25 pm ] |
Post subject: | Re: sunrise, sunset, moonrise, and moonset in 12 hr time |
edit: i didn't noticed that you have done with removing 0 from it, so have this one as another way; ================== and some tips: i forgot to tell, you can also use [accweathercore] for update instead of [datetimecore]; (to lower the resource usage) ================== just added this line to previous code, this will convert the string to integer: Code: tmp1[0]=parseInt(tmp1[0],10) here's the full code: Code: function datetimecore1OnUpdate(Sender)
{ //sunrise tmp1=accweathercore1.get("%sunRise").split(":") tmp1[0]= parseInt(tmp1[0],10) if(tmp1[0]>12) { tmp1[0]=tmp1[0]-12 sunrise.Text="Sunrise: "+tmp1[0]+":"+tmp1[1]+" PM" } else if(tmp1[0]==0) { sunrise.Text="Sunrise: "+12+":"+tmp1[1]+" AM" } else if(tmp1[0]==12) { sunrise.Text="Sunrise: "+12+":"+tmp1[1]+" PM" } else if(tmp1[0]<12) { sunrise.Text="Sunrise: "+tmp1[0]+":"+tmp1[1]+" AM" } //sunset tmp1=accweathercore1.get("%sunSet").split(":") tmp1[0]=parseInt(tmp1[0],10) if(tmp1[0]>12) { tmp1[0]=tmp1[0]-12 sunset.Text="Sunset: "+tmp1[0]+":"+tmp1[1]+" PM" } else if(tmp1[0]==0) { sunset.Text="Sunset: "+12+":"+tmp1[1]+" AM" } else if(tmp1[0]==12) { sunset.Text="Sunset: "+12+":"+tmp1[1]+" PM" } else if(tmp1[0]<12) { sunset.Text="Sunset: "+tmp1[0]+":"+tmp1[1]+" AM" } } |
Page 1 of 1 | All times are UTC - 8 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |