LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-21-2018, 05:17 PM   #1
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Rep: Reputation: 17
Setting Time zone with TZ environment variable


On an embedded Debian ARM system for which I am programming the C localtime function returns the UTC time rather than the local time. I searched the Net and found out this was because the TZ environment variable is not set.

Booting into other Linux distros ( Ubuntu, Fedora ) I notice that the TZ environment variable is not set for myself as a login user, and yet the 'date' command gives the local time correctly.

Can someone tell me why a Linux distro which does not have the TZ environment variable set gives the correct local time when I issue the 'date' command but the embedded Debian ARM system for which I am programming, which also has no TZ environment variable set, gives me the UTC time when I issue the 'date' command ?

The question is how I get the embedded Debian ARM system to have the correct local time. Maybe I need to ask that on some Debian forum, but I thought I would try here to try to get some insight into this problem.
 
Old 02-21-2018, 05:44 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Not sure what the problem is, but maybe the timezone man page will help:
Code:
man 3 tzset
 
Old 02-21-2018, 06:19 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,813

Rep: Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958
None of my desktop systems set the TZ environment variable. If TZ is not set then date uses the default system rules which is /etc/timezone.

Is the timezone database installed on your embedded system? Does /usr/share/zoneinfo exist?
 
Old 02-22-2018, 09:14 AM   #4
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by michaelk View Post
None of my desktop systems set the TZ environment variable. If TZ is not set then date uses the default system rules which is /etc/timezone.

Is the timezone database installed on your embedded system? Does /usr/share/zoneinfo exist?
Yes /usr/share/zoneinfo does exist.

I found out that using the command:

timedatectl set-timezone some_time_zone

will permanently set the time zone for the system.

Thanks for your help !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Time Zone configuration with TZ environmental variable hellolqs Linux - General 2 02-08-2012 10:25 AM
Setting time and time zone altogether properly in Slack-current, KDE4 spaceballs Slackware 3 04-20-2011 05:15 AM
Problems setting time and time zone in RH Linux am_mitra Linux - Newbie 1 12-03-2008 08:09 PM
Setting environment variable to current date/time nafan Programming 1 08-23-2004 09:04 PM
Setting System Time: kernel in wrong time zone warrenweiss Linux - General 7 05-15-2004 03:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration