473,324 Members | 2,166 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,324 software developers and data experts.

Time offset from UTC

Hello all,

For a program I want to fix, I need to find a portable way to get
the offset from local time to UTC (coming from the Time Zone plus
any daylight savings in effect).

At first glance, the following seems to be OK:

time_t t;
int timeoffset;
t = time (NULL);
timeoffset = (int) difftime (t, mktime(gmtime(&t))); /* seconds */

My concern is the above code's portability. I'm thinking at:

(a) Is mktime() always the inverse of localtime(), or it may use
implementation-dependent fields in struct tm, that may specify
TZ info, for it's calculations? (In such a case, gmtime() may store

UTC+00:00 in the structure, and I get timeoffset always 0.)
(b) Assuming localtime() succeeds, is there any good reason for
gmtime()
to fail? (like a system and C run-time that has absolutely no
knowledge about time-zones, not even an arbitray default.)

Any comments, suggestions? Is there a better way?

Thanks in advance,
sags

Nov 15 '05 #1
0 1652

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

Similar topics

1
by: ian douglas | last post by:
Hey all. I know with Perl "there's more than one way to do it", but I'd rather not reinvent the wheel... /usr/share/zoneinfo/Etc/ contains files like GMT-5 or GMT+8 etc which would be really...
2
by: Peter Kleiweg | last post by:
Is there a safe and clean way to parse a date/time string into seconds since epoch? I have a string with date and time in GMT. I can get the correct value using this: #!/usr/bin/env python...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
5
by: RICHARD BROMBERG | last post by:
I am writing an ASP program that includes a Form. When the Form is submitted I use the Date() and Time() functions to put the date and time into the Body part of the e-mail. The time reported is...
4
by: __jakal__ | last post by:
Hello, I need to find out the time difference between UTC and local time. I am doing it the following way #include <sys/timeb.h> #include <stdio.h> int main() { struct timeb tp; ftime(&tp);
8
by: Nathan Sokalski | last post by:
I use a webhosting service that is something like halfway around the world from me and most of the people that will be viewing my site (and I am assuming their server is too). This obviously has...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
2
by: ZR | last post by:
Hello, I need to convert a GMT time string to local time. I can fill out a "tm" structure with the GMT time string. Are there any standard C (or OS) time functions that will allow me to do this? ...
4
by: Polaris431 | last post by:
I have a web application in ASP.NET that will be used globally. Data is collected on mobile devices running Windows Mobile and sent to the web server where it is stored and can be viewed. Data is...
4
by: Gabriel Rossetti | last post by:
Hello everyone! I trying to work with time and I a bit confused... If I look at my clock, it's 16:59 (4:59pm), if I type "date" in a terminal, it says the same thing. I'm wanting to write a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.