Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Nov 2004 13:10:01 +0100
From:      =?iso-8859-1?Q?Jimmy_M=E4kel=E4_|_Loopia_Webbhotell_AB?= <jimmy.makela@loopia.se>
To:        <freebsd-questions@freebsd.org>
Subject:   Timezone conversion
Message-ID:  <045701c4d543$2ff2c160$c600a8c0@i11>

next in thread | raw e-mail | index | archive | help
Hi

I'm trying to convert a date from one timezone into another using the 
date-command, but I can't seem to get it to work.

The problem can be illustrated as below, though in reality I get the date 
from another source of course, otherwise I wouldn't have to do this.

Take a date in some timezone other than your own, in this example I generate 
the current time in UTC:
> TZ=UTC date +"%d %b %Y %H:%M:%S %z"
28 Nov 2004 12:02:18 +0000

Try to use date -j to convert a date of this format into the default 
display-format:
> TZ=CET date -j -f "%d %b %Y %H:%M:%S %z" "28 Nov 2004 12:02:18 +0000"
Warning: Ignoring 5 extraneous characters in date string (+0000)
Sun Nov 28 12:02:18 CET 2004

The result is wrong of course because the timezone is ignored even though i 
specify %z in the format-string. The date in CET should be 13:02:18.

Now the question; does anyone know why the %z is ignored? Am I missing 
something, and if so what?

The man-page for the -f parameter states "Parsing is done using 
strptime(3)." and since strptime allows %z I was assuming that the example 
above should work.

I would be really thankful for some help in getting around this.

Thanks in advance.

Best regards,
Jimmy Mäkelä 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?045701c4d543$2ff2c160$c600a8c0>