# Time conversions

• 01-02-2004
mariabair
Time conversions
I am generating a clock for my MFC application that figures out what the current time is based on the selected timezone. What I need to do is calculate an offset using the system time. I get GMT time and figure out what the time is based on an offset, for instance I will calculate what MST is and update the clock to display the current time in the MST timezone.

Is there a function that will allow me to do this? For example in Java the "Calandar" object has a member function "add", Calendar.add that takes two values ( Calendar.HOURS, offset) and does the addition for you.
Example: Calendar cal;

THIS IS WHAT I HAVE USED FOR MY C++ CODE SO FAR

Code:

```              time_t now;         struct tm *tm_now;         int hour;         int minutes;         int new_hour;         now = time ( NULL );         tm_now = gmtime ( &now );                 hours = tm_now->tm_hour;```
• 01-02-2004
assuming what you have works and gives hours in range 0 - 23, then this sequence should get hours adjusted by offset.

hours += offset;
if(hours < 0)
hours = 24 + hours;
if(hours >= 24)
hours = hours - 24;
//for AM/PM
if(hours == 0)
hours = 12
else(hours > 12)
hours -= 12;
• 01-02-2004
mariabair
Thank YOU