473,412 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Difference between local time and UTC

I am trying to find the best way to get the difference between UTC and
the local time? Here's a small code snippet that I have written for
this purpose. Is there a better way to do this?

Thanks,
Bala

/************************************************** ***********************/
time_t getTimeOffset()
{
struct tm *gmTime;

time_t localEpoch, gmEpoch;

/*First get local epoch time*/
localEpoch = time(NULL);

/* Using local time epoch get the GM Time */
gmTime = gmtime(&localEpoch);

/* Convert gm time in to epoch format */
gmEpoch = mktime(gmTime);

/* get the absolute different between them */
return abs(gmEpoch - localEpoch);
}

May 22 '06 #1
1 5595


Generic Usenet Account wrote On 05/22/06 15:42,:
I am trying to find the best way to get the difference between UTC and
the local time? Here's a small code snippet that I have written for
this purpose. Is there a better way to do this?

Thanks,
Bala

/************************************************** ***********************/
time_t getTimeOffset()
{
struct tm *gmTime;

time_t localEpoch, gmEpoch;

/*First get local epoch time*/
localEpoch = time(NULL);

/* Using local time epoch get the GM Time */
gmTime = gmtime(&localEpoch);

/* Convert gm time in to epoch format */
gmEpoch = mktime(gmTime);

/* get the absolute different between them */
return abs(gmEpoch - localEpoch);


Use difftime(gmEpoch, localEpoch) instead, and have
the function return a double. This makes things work
even on systems where time_t may be encoded in some other
way than a count of seconds elapsed since a Zero time.

Some error-checking would be a good idea, too. Yes,
there are systems that don't have calendar clocks, and
even among those that do there are some that simply run
their clocks in local time and have no notion of other
time zones.

--
Er*********@sun.com

May 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DraguVaso | last post by:
Hi, I'm new to WebServices, and I'm doing some tests (with a small VB.NET-application) to know the performance-difference between a WebService and the 'normal'-way of getting data (just...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
8
by: James | last post by:
Can someone explain the fundamental difference between creating a "multi user" version of an Access DB and creating a client-server Access DB? ie why can't all the users on my network just click...
14
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
3
by: rrs.matrix | last post by:
i have a problem i have a file which contains the time and is generated on sun machine. i have to decode the time on linux machine. the problem is that the sun machine shows different time and the...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
3
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.