timezone command

Matthew Seaman m.seaman at infracaninophile.co.uk
Fri Apr 16 09:18:02 PDT 2004

On Fri, Apr 16, 2004 at 11:48:11AM -0400, JJB wrote:
> Yes that is close enough for an starting point, thank you.
> I need $timezone to hold the time zone in this format  -00:00
> The command date +%z  will give it as  -0000
> I know nothing about writing perl scripts.
> Can somebody show me how to  add the : in the output
> of the date command in the simple following script?
> The cat statement is just so I can see results are correct.
> #!/usr/bin/perl
> $timezone=date +%z;
> cat $timezone

You can do it very easily with perl:

    #!/usr/bin/perl -w

    use POSIX (strftime);

    ($d = strftime("%z", localtime)) =~ s/(\d\d)(\d\d)/$1:$2/;

    print "$d\n";

but it's probably a bit too heavyweight to use perl to format the
string if you aren't already writing a whole script in perl.  Instead,

    date +%z | sed -e 's,\([0-9][0-9]\)\([0-9][0-9]\),\1:\2,'



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040416/20bc39e5/attachment-0001.bin

More information about the freebsd-questions mailing list