# Correct time zone does but date's output is wrong



## quamenzullo (Oct 12, 2014)

Hello,

After a fresh FreeBSD 10 install, with everything updated and upgraded (FreeBSD 10.0-RELEASE-p2), if I do `# cp /usr/share/zoneinfo/Europe/Paris /etc/localtime` then `date` displays a time that's 6 hours ahead from the right one in France.

The time offset between Paris and UTC seems correct though:

```
# date "+%z"
+0200
```

And if I do `# cp /usr/share/zoneinfo/UTC /etc/localtime` then `date` displays a time that's 6 hours ahead from UTC.

I tried to use `tzsetup`, but the result is the same, whether telling tzsetup that the CMOS clock is set to UTC or not. Actually, as the box is a server (that I rent from a company), I don't know if the CMOS clock is set to UTC or not, so I tried both options.

Another hint: the server is not in France, but in Canada I think. If I set the time zone to Montreal, then `date` displays the right time (for France!) but when using sendmail to send an e-mail, then the e-mail's timestamp is not correct. This location in Canada could be a hint to understand the reason of this 6 hours offset, but it doesn't explain why the UTC time is wrong, nor why the e-mail timestamps do not match system time.

Before I set the timezone to Paris for the first time, if I used `date hhmm` to set the time, then `date` would display the right time, but when using for instance sendmail to send an e-mail, the e-mail timestamp was still wrong.

After I set the timezone to Paris, as the time was wrong, I had to use `date hhmm` to set the time, but then not only `date` finally displays the right time, but e-mail timestamps too are correct.

So, I can keep these settings, they don't prevent me from using the server, but still: I wonder why, when setting time zone to UTC there is this 6 hours offset.

Can anyone explain that? And if possible, if there's something I've missed, if my timezone / time / date configuration could be done in a better way?


----------



## freethread (Oct 13, 2014)

tzsetup should do the same thing, perhaps better. It's a TUI command to manually select the timezone (or specify it on command line for no TUI).


----------



## quamenzullo (Oct 13, 2014)

Thanks for your answer, but:



			
				quamenzullo said:
			
		

> I tried to use `tzsetup`, but the result is the same, whether telling tzsetup that the CMOS clock is set to UTC or not. Actually, as the box is a server (that I rent from a company), I don't know if the CMOS clock is set to UTC or not, so I tried both options.


----------



## freethread (Oct 13, 2014)

Ehm, I miss something. Ok, after tzsetup the system is at the location specified, in your case Canada. You are logged in as a user, if the timezone of the user is the same of the system the time is unique, if not the user time is in the timezone of the user



> ...then date displays the right time (for France!)...



I guess the timezone of the account used (root or whatelse) in set to CET. I think the system use system time for operations that depend on it (services), so e-mail times are in system timezone.


----------



## quamenzullo (Oct 13, 2014)

freethread said:
			
		

> I guess the timezone of the account used (root or whatelse) in set to CET.



Not CET, but CEST:


```
# date
Mon Oct 13 23:00:31 CEST 2014
#
```

And there's still a problem, actually, mysql is six hours late:


```
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2014-10-13 17:01:18 |
+---------------------+
1 row in set (0.00 sec)

mysql>
```

I'll try to set mysql time zone, there are ways to do that. I hope it won't disturb the other settings!


----------



## freethread (Oct 14, 2014)

Thinking about timezones, in my opinion, the behaviour you see is correct. The system is in system timezone (Canada) and all the system services use that time, for programs/commands ran by user the user's timezone is used (France).

The time has significance for administrators, perhaps it's not geographically correct but setting the system timezone as the same as the administrator's timezone doesn't matter a lot (unless, ethical, political, social, sacred, aliens, whatever restriction exists).

The timezone in MySQL can be changed in the ini file, see also this page http://dev.mysql.com/downloads/timezones.html


----------



## quamenzullo (Oct 15, 2014)

freethread said:
			
		

> Thinking about timezones, in my opinion, the behaviour you see is correct. The system is in system timezone (Canada) and all the system services use that time, for programs/commands ran by user the user's timezone is used (France).



OK, so there's one point I would like to understand better: you talk about two different timezones: the system's one and the user's one. Whereas anywhere I've only explanations about setting the time (no more detail). If there are two different timezones, then there should be a way to get and set both of them separately.

For instance, when @root uses `date` to set the time, which one is set then, the system's one, or @root's one?


----------



## freethread (Oct 18, 2014)

The system uses root user time, or the system time and root user time are the same. I never set two different timezones for _the_ root user (system time) and another user (normal user, in _the_ wheel group or not).


----------



## kpa (Oct 18, 2014)

So called local time for user space programs is what is set in /etc/localtime or in the TZ environment variable if set (see tzset(3)).

The kernel's internal time is always in UTC but the hardware clock can be either local time or UTC, this is controlled by a file /etc/wall_cmos_clock and if it exists the hardware clock is in local time.


----------

