ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I did not find code to automatically set up this variable,
Functions in time.h do explain in a way, how to go about it.
Since I needed a system that was current between Unix (all) and Linux(all) and BSD(all), I wrote a quick and simple bit of code that provides me the number of hours of difference, I had to write two lines to a file, One being UTC, and the other, localtime, and subtract one from the other. I also had to accomodate midnight crossing.
Here is the snippit or code.
int getTimeOffset()
{
FILE *file;
int hr1, hr2, rc;
char buffer[64];
system ("date +%H >/tmp/TZ");
system ("date -u +%H >>/tmp/TZ");
TZ environment variable. One standard, not in Fedora, is the TZ variable.
Then it's not exactly a standard, is it?
Quote:
Originally Posted by Lsatenstein
Since I needed a system that was current between Unix (all) and Linux(all) and BSD(all), I wrote a quick and simple bit of code that provides me the number of hours of difference, I had to write two lines to a file, One being UTC, and the other, localtime, and subtract one from the other. I also had to accomodate midnight crossing.
Here is the snippit or code.
int getTimeOffset()
{
FILE *file;
int hr1, hr2, rc;
char buffer[64];
system ("date +%H >/tmp/TZ");
system ("date -u +%H >>/tmp/TZ");
I looked at the time.h stuff, and it may be the way to go. The above took me all of 10 minutes,
I needed the value, once per execution. I am scanning a full directory tree, and the time shown when you do ls -l is UTC with offset of (4 * 3600) seconds.
Its also very short. (grin)
[leslie@Fedora20 ~]$ date
Fri Apr 4 20:29:04 CDT 2014
[leslie@Fedora20 ~]$ date -u
Sat Apr 5 01:29:08 UTC 2014
[leslie@Fedora20 ~]$
I reside at gmt-5 so 20:30 is actually 1:30 gmt time
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.