Ad
How To Calculate Offset Of 4 Hours And 30 Minutes Within Function WorldClockZone
I want to calculate below code with 4 hours and 30 minutes to GMT but I have no idea to add 30 minutes in this code, can anyone help me?
function worldClockZone(){
document.getElementById("Dehli").innerHTML = worldClock(4, "India")
While Dehli is City, 4 is the time offset (which I need to 04:30 instead) and India is region.
Thanks in advance
Ad
Answer
I'm going to assume you are using the following code:
https://www.proglogic.com/code/javascript/time/worldclock.php
The code seems to match, so I'll give it a go as it's generic enough and might be of use to others as well. As is, the function worldClock
does not support this behaviour. However, you could do some tinkering. Add the following:
// handle float
var remainder = Math.floor( ( zone % 1 ) * 60 )
zone = Math.floor( zone )
before adding the zone parameter to hr
:
var hr = gmtTime.getHours() + zone
var min = gmtTime.getMinutes()
var sec = gmtTime.getSeconds()
afterwards handling the remaining minutes:
// make sure to adjust hr and min accordingly
min += Math.abs( remainder )
hr += ( remainder != 0 && min >= 60 ? 1 : 0 )
min %= 60
and then call:
function worldClockZone(){
document.getElementById("Dehli").innerHTML = worldClock(4.5, "India")
This should work for all float numbers, including negatives.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad