Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, November 2, 2015

Get month name from Date

http://stackoverflow.com/questions/1643320/get-month-name-from-date
How can I generate the name of the month (e.g: Oct/October) from this date object in JavaScript?
var objDate = new Date("10/11/2009");
shareimprove this question

20 Answers

up vote409down voteaccepted
Shorter version:
var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];

var d = new Date();
document.write("The current month is " + monthNames[d.getMonth()]);
shareimprove this answer

Monday, September 28, 2015

when radio button is selected, a popup box should display the text of the radio button

<script type="text/javascript">
function radioEvent(form) 
{
 for (var i = 0; i < form.radioButton.length; i++) 
 {
    if (form.radioButton[i].checked)
    {
        alert("You chose " + form.radioButton[i].value + ".")
    }
 }
 }
</script>
</head>
<body>
<form>
<input type="radio" name= "radioButton" value= "Excellent"   onclick="radioEvent(this.form);"/> Excellent<br/>
<input type="radio" name="radioButton"  value="Very Good" onclick="radioEvent(this.form);"/> Very Good <br/>
<input type="radio" name="radioButton"  value="Good" onclick="radioEvent(this.form);"/> Good <br/>
<input type="radio" name="radioButton"  value="Satisfactory" onclick="radioEvent(this.form);"/> Satisfactory
</form>
</body>
</html>
shareimprove this answer
   
Thank you for the above code.Is it the same procedure for drop-down box, check box and text input too? – Navya Akkiraju Oct 13 '12 at 23:14 
   
yes, just change type of Input tag –  vinus patel Oct 15 '12 at 1:43

Sunday, September 13, 2015

The easy way to get java TimeZone from latitude/longitude

JavaGroovy
Branch: master 
latest commit c79ee3cd6b
@agap  authored 

 README.md

What llttz is?

llttz (stands for latitude longitude ttime zone) is a light-weight project written in Java which allows you to obtain the time zone in a place with specified latitude and longitude. Original idea (along with the dataset) was taken from the APTimezones project. To obtain the TimeZone you need to create an object of Converter class, and invoke its getInstance(double lat, double lon) method, like so:
IConverter iconv = Converter.getInstance(TimeZoneListStore.class);
TimeZone tz = iconv.getTimeZone(53.5233333, 49.4125);
Here TimeZoneListStore is a class which holds a list of timezones. The time complexity of nearest neighbor search is O(n) in that case. There is also another class, named TimeZoneTreeStore, which you can use to perform nearest neighbor searches. It holds a simple implementation of k-d tree which can perform nearest neighbor lookup with the time complexity of 0(ln(n)) in the best case (it's a little bit unstable and returns wrong timezones when we perform searches in the areas which are located near the South or North Pole so you can stick to TimeZoneListStore for now).

I see that you're using a list of timezones here instead of the list of timezones' polygones. The calculated time zone won't be precise, right?

Yes, in some cases you can get the error in +\- 2 hours.

Is it useful then?

It depends. In my case I needed library which could allow me to calculate the time zone by provided latitude/longitude without making requests to remote web-services, such as GeoNames. I also needed this library to be a light-weight (I had to use it on Android devices) and preciseness in calculations wasn't the mandatory requirement. https://github.com/agap/llttz