viewed 3750 times and licensed 15 times
Returns the time offset between two world locations
View version details
Contents  |
|
Interface
#include <codecogs/units/time/worldtimediff.h>
using namespace Units::Time;
| double | worldTimeDiff (worldTimeZone LocA, worldTimeZone LocB)[inline] Returns the time offset between two world locations |
Function Documentation
Returns the difference in time between two location around the world, as a fraction of a day. The enumerated
worldTimeZone locations contain the difference (in hours * 10) between Greenwich Mean Time (GMT) and the stated location. Therefore these enumerated values can be used explicitly to give the difference in time between two locations, for example: The difference in time between Moscow and New York is:
(wt_US_Canada_EasternTime - wt_Moscow)/10.0
Once you add in the addition factor of 1/24 to produce the fractional part of a day, the code for this module simply becomes:
inline double worldTimeDiff(worldTimeZone LocA, worldTimeZone LocB)
{
return (LocA - LocB)/(24 * 10.0); // to get fractions of a day
}
Therefore in most instances you may prefer to do this calculations directly.
Examples:
This example gives you the standard times in NewYork, Paris and London. It assumes the computer is based in London.
#include <stdio.h>
#include <codecogs/units/time/now.h>
#include <codecogs/units/time/worldtimediff.h>
#include <codecogs/units/time/timehms.h>
using namespace Units::Time;
void main()
{
double london=now(st_None);
double ny=london + worldTimeDiff(wt_US_Canada_EasternTime, wt_London);
double paris=london + worldTimeDiff(wt_Paris, wt_London);
int h,m,s;
timeHMS(london, h,m,s);
printf("\n Standard time in London is: %02d:%02d:%02d", h,m,s);
timeHMS(ny, h,m,s);
printf("\n Standard time in New York is: %02d:%02d:%02d", h,m,s);
timeHMS(paris, h,m,s);
printf("\n Standard time in Paris is: %02d:%02d:%02d", h,m,s);
}
A simple extension, using
summerTime, ensures that summer time is applied (as appropriate), i.e
timeHMS(london + summerTime(london, st_UK)/24.0, h,m,s);
printf("\n The time in London is: %02d:%02d:%02d", h,m,s);
timeHMS(ny + summerTime(london, st_USA)/24.0, h,m,s);
printf("\n The time in New York is: %02d:%02d:%02d", h,m,s);
timeHMS(paris + summerTime(london, st_EU)/24.0, h,m,s);
printf("\n The time in Paris is: %02d:%02d:%02d", h,m,s);Parameters:
| LocA | first time zone |
| LocB | second time zone |
Returns:
- the fraction of a 24hr between the two locations
Authors:
- Will Bateman (Nov 2004)
Page Comments
You must login to leave a messge
Last Modified: 18 Oct 07 @ 17:07 Page Rendered: 2010-03-14 10:39:36