Posts

Showing posts with the label jquery

Display time according to the timezone using Javascript.

I have got many query that many people are confuse to get the local time zone using JavaScript as server are mainly saves in UTC or GMT time. If you are using ajax which gives time but the time you get is of server time like, jQuery.post("link",{para meter} ,function(data){ var time=data; <!-----data may be the time-----> var t= time.split(/[- :]/); <!------first split the time -----> var change = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]); var nowUtc = new Date( change.getTime() -((change.getTimezoneOffset()*60000)) ); <!--change.getTimezoneOffset() gives the local time different i.e. if you are at Kathmandu, the time different is +5:45, this gives 345min--> var final_hr=nowUtc.getHours(); var final_min=nowUtc.getMinutes(); //for minute i.e. from 1-9 placing '0' in front if(final_min.toString().length==1){var minute='0'+final_min;} else{var minute=final_min;} //for date var date=nowUtc.getDate(); //for date suffix if (da