# hwclock --utc == local time, --localtime == UTC time?

## pachanga

Guys i'm a bit confused with results of querying hwclock.

My local time is GMT + 4, so first i set my system time using "date". Then i set hwclock using "hwclock --systohc --utc" command in order to have my RTC in UTC. However querying hwclock reveals a bit confusing results:

```

# hwclock --utc

Thu Jul 28 15:14:13 2005  -0.530722 seconds

```

```

# hwclock --localtime

Thu Jul 28 11:14:40 2005  -0.476347 seconds

```

It seems it prints local time with --utc switch and its actual internal time with --localtime switch, right? If yes, why not vice versa? It would be more logical IMHO...Last edited by pachanga on Fri Jul 29, 2005 8:19 am; edited 2 times in total

----------

## RiBBiT

For me it's the other way around.

----------

## pachanga

 *RiBBiT wrote:*   

> For me it's the other way around.

 

Do you mean running hwclock --utc returns UTC time?

----------

## RiBBiT

That's exactly what I meant. However I just discovered I was wrong, my hardware clock had been f*cked up by my Windows installation so it was set to local time. hwclock --utc indeed seems to display the local time while hwclock --localtime displays UTC, weird.

----------

## irasnyd

Same thing is happening here. I haven't had windows on this machine in almost a year.

```

yuki ~ # date

Thu Jul 28 22:47:01 PDT 2005

yuki ~ # hwclock --utc

Thu Jul 28 22:47:08 2005  -0.287794 seconds

yuki ~ # hwclock --localtime

Fri Jul 29 05:47:14 2005  -0.328052 seconds

yuki ~ # ls -l /etc/localtime

lrwxrwxrwx  1 root root 39 Feb 18 16:51 /etc/localtime -> /usr/share/zoneinfo/America/Los_Angeles

yuki ~ # hwclock -w --utc

yuki ~ # hwclock --utc

Thu Jul 28 22:48:18 2005  -0.997177 seconds

yuki ~ # hwclock --localtime

Fri Jul 29 05:48:22 2005  -0.397110 seconds

```

And here is my /etc/conf.d/clock file:

```

# /etc/conf.d/clock

# Set CLOCK to "UTC" if your system clock is set to UTC (also known as

# Greenwich Mean Time).  If your clock is set to the local time, then

# set CLOCK to "local".

CLOCK="UTC"

# If you wish to pass any other arguments to hwclock during bootup,

# you may do so here.

CLOCK_OPTS=""

# If you want to set the Hardware Clock to the current System Time

# during shutdown, then say "yes" here.

CLOCK_SYSTOHC="yes"

### ALPHA SPECIFIC OPTIONS ###

# If your alpha uses the SRM console, set this to "yes".

SRM="no"

# If your alpha uses the ARC console, set this to "yes".

ARC="no"

```

How did you get it fixed? I can't seem to get my clock set to UTC. I thought it was for all this time. "date" has been working fine, although I have been seeing some weird times in my logs. Maybe this is related.

Thanks.

----------

## pachanga

 *irasnyd wrote:*   

> 
> 
> How did you get it fixed? I can't seem to get my clock set to UTC. 
> 
> 

 

If you're talking about RTC, try 

```

hwclock --systohc --utc

```

This should set your hardware clock equal to system clock and mark it as UTC time.

----------

## pachanga

 *RiBBiT wrote:*   

>  hwclock --utc indeed seems to display the local time while hwclock --localtime displays UTC, weird.

 

Maybe that's ok? Well i can live with that but they should point this issue more explicitly in man then IMHO...

----------

## Kaapeli

 *pachanga wrote:*   

>  *irasnyd wrote:*   
> 
> How did you get it fixed? I can't seem to get my clock set to UTC. 
> 
>  
> ...

 

Doesn't this do it automatically correctly:

```

/etc/init.d/clock save

```

----------

## pachanga

Well, anyway the question remains - is this behaviour of hwclock ok???

----------

## RiBBiT

I think I discovered why it seems wrong. hwclock ALWAYS displays the local time. --utc tells hwclock it is set by UTC and the timezone modifier is applied to the time before it is displayed. If --localtime is used hwclock thinks it is already synced with local time and the timezone modifier is not applied.

----------

## pachanga

 *RiBBiT wrote:*   

> I think I discovered why it seems wrong. hwclock ALWAYS displays the local time. --utc tells hwclock it is set by UTC and the timezone modifier is applied to the time before it is displayed. If --localtime is used hwclock thinks it is already synced with local time and the timezone modifier is not applied.

 

Still pretty weird, isn't it?

----------

## RiBBiT

 *pachanga wrote:*   

>  *RiBBiT wrote:*   I think I discovered why it seems wrong. hwclock ALWAYS displays the local time. --utc tells hwclock it is set by UTC and the timezone modifier is applied to the time before it is displayed. If --localtime is used hwclock thinks it is already synced with local time and the timezone modifier is not applied. 
> 
> Still pretty weird, isn't it?

 

Not very weird when you think about it. hwclock have no means to know if it set by UTC or local time by it self, so asking it to display the time of the current system (which is always local time) makes no sense if you don't tell it what timezone it is set by in the first place.

----------

## CarlosAB

So, how can someone like me can setup his RTC and system clock, with "/etc/init.d/clock" and his step brother "/etc/conf.d/clock", to work togheter as a team.

Thanks

Carlos[/code]

----------

## firekopf

okay, I'm having a similar problem with my hwclock. Whenever I type hwclock it says it 'timed out waiting for time change' so the hwclock is not set, meaning it defaults to January 1, 1970 for some reason. I can change the software clock with date but I don't want to have to do that every boot.

Anyone have a solution?

----------

## RiBBiT

 *firekopf wrote:*   

> okay, I'm having a similar problem with my hwclock. Whenever I type hwclock it says it 'timed out waiting for time change' so the hwclock is not set, meaning it defaults to January 1, 1970 for some reason. I can change the software clock with date but I don't want to have to do that every boot.
> 
> Anyone have a solution?

 

Could it be your BIOS battery that's running low? The reason your hardware clock is set to January 1, 1970 is because that is the base of most computer clocks. The current time is expressed as a number of seconds from  January 1, 1970. 19:15:34 today, for an example, is 1123348534 seconds from January 1, 1970. If you don't want to change the clock manually every boot you can use some NTP application (emerge ntp).

----------

## firekopf

I'm not sure the actual physical hardware clock is the problem. Wouldn't it still be able to detect a tick when it had main power? The clock on my Mac OS partition functions fine, which I don't think it would if the actual clock ran out of juice.

----------

## RiBBiT

Do you have clock set up to start at boot (rc-update show)? Can you post your /etc/conf.d/clock?

----------

## firekopf

just out of curiosity, its probably a bad sign that I don't have /etc/conf.d/clock?

----------

## theWebster

arrgh!! I think I finally got this working, but I'm confused by the redundancies I see and have yet 

to check what happens if I try setting the time in KDE (not that I should *ever* have to do so again...!!!) 

Anyhow, my hwclock, date and localtime all reported UTC time. I checked that /etc/timezone was set OK, 

but had failed to notice that somewhere along the way the /etc/localtime had VANISHED. So, after

```
ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime
```

 it is looking fixed.

I'm using 

```
emerge ntp
```

```
# /etc/conf.d/ntp-client

NTPCLIENT_CMD="ntpdate"

NTPCLIENT_OPTS=" -b -u 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org"

NTPCLIENT_TIMEOUT=30

```

```
# /etc/conf.d/clock

CLOCK="local"

CLOCK_OPTS=""

CLOCK_SYSTOHC="no"

SRM="no"

ARC="no"

```

```
# /etc/conf.d/ntpd

NTPD_OPTS="-u ntp:ntp"

```

HTH, it has been about the most irritating item so far, but I've been away for several years as the weeks 

it took to get as far as a CLI was too frustrating. I have however, in two days, got through wiping all I had 

before and installing fresh from Stage 3 tarball and minimal CD, to an incredibly awesome dazzling KDE 

complete with a dozen or two goodies beyond the default base, including koffice, samba and support for 

my nForce ethernet (that last being #2 irritation...) I am feeling about the same as when I first succeeded 

in creating a PPP connection and fired up the then-brand-new Netscape. I believe gentoo will save mankind, I do.

----------

