Re: timezone command

2004-04-16 Thread Shaun Friedle
On Fri, 2004-04-16 at 17:17, Matthew Seaman wrote:
> 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,
> try:
> 
> date +%z | sed -e 's,\([0-9][0-9]\)\([0-9][0-9]\),\1:\2,'
> 
>   Cheers,
> 
>   Matthew


Oops, didn't notice this because it was in a different thread. Well now
you  have two Perl solutions :)
-- 
Shaun Friedle

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: timezone command

2004-04-16 Thread Matthew Seaman
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  -
> 
> 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,
try:

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

Cheers,

Matthew

-- 
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


pgp0.pgp
Description: PGP signature


RE: timezone command

2004-04-16 Thread JJB
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  -

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


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Erik
Trulsson
Sent: Friday, April 16, 2004 1:01 AM
To: JJB
Cc: Greg 'groggy' Lehey; [EMAIL PROTECTED] ORG
Subject: Re: timezone command

On Fri, Apr 16, 2004 at 12:28:58AM -0400, JJB wrote:
> I know how to set timezone, date and time.
>
> I am looking for command to display on the console screen the
> systems timezone in this kind of format "-00:00"
>
> Is there such an command or some way to get this info?
>
> In an perl script I tried  $timezone= $ENV{TZ}  and I did not get
> 00:00 format which I was looking for.

Try 'date +%z' to get the timezone in the format "+0200".
Not exactly what you asked for, but almost.


--

Erik Trulsson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to
"[EMAIL PROTECTED]"

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: timezone command

2004-04-15 Thread Erik Trulsson
On Fri, Apr 16, 2004 at 12:28:58AM -0400, JJB wrote:
> I know how to set timezone, date and time.
> 
> I am looking for command to display on the console screen the
> systems timezone in this kind of format "-00:00"
> 
> Is there such an command or some way to get this info?
> 
> In an perl script I tried  $timezone= $ENV{TZ}  and I did not get
> 00:00 format which I was looking for.

Try 'date +%z' to get the timezone in the format "+0200".
Not exactly what you asked for, but almost.


-- 

Erik Trulsson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: timezone command

2004-04-15 Thread JJB
I know how to set timezone, date and time.

I am looking for command to display on the console screen the
systems timezone in this kind of format "-00:00"

Is there such an command or some way to get this info?

In an perl script I tried  $timezone= $ENV{TZ}  and I did not get
00:00 format which I was looking for.

-Original Message-
From: Greg 'groggy' Lehey [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 11:58 PM
To: JJB
Cc: [EMAIL PROTECTED] ORG
Subject: Re: timezone command

On Thursday, 15 April 2004 at 22:15:06 -0400, JJB wrote:
> Time zone has been set during sysinstall.
> Is there an console command to display my configured time zone
like
> format +05:00?

Not quite like that (are you in Pakistan?).  The problem is that
time
zones aren't that simple: they contain information about daylight
savings time, as well as implicit historical information that gets
lost when you reduce it to a number.  Admittedly, Pakistan doesn't
seem to have DST, but that's the way it is.

In general, the system time zone is stored in the file
/etc/localtime.
You can set it with:

  # cp /usr/share/zoneinfo/Asia/Karachi /etc/localtime
  # date
  Fri Apr 16 08:55:27 PKT 2004

If you remove it, it defaults to "GMT" (really UTC):

  # rm /etc/localtime
  # date
  Fri Apr 16 03:55:37 GMT 2004

Even then, you can specify the time zone explicitly with the TZ
environment variable:

  # TZ=Asia/Karachi date
  Fri Apr 16 08:55:45 PKT 2004

Greg
--
When replying to this message, please copy the original recipients.
If you don't, I may ignore the reply or reply to the original
recipients.
For more information, see http://www.lemis.com/questions.html
Note: I discard all HTML mail unseen.
Finger [EMAIL PROTECTED] for PGP public key.
See complete headers for address and phone numbers.

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: timezone command

2004-04-15 Thread Greg 'groggy' Lehey
On Thursday, 15 April 2004 at 22:15:06 -0400, JJB wrote:
> Time zone has been set during sysinstall.
> Is there an console command to display my configured time zone like
> format +05:00?

Not quite like that (are you in Pakistan?).  The problem is that time
zones aren't that simple: they contain information about daylight
savings time, as well as implicit historical information that gets
lost when you reduce it to a number.  Admittedly, Pakistan doesn't
seem to have DST, but that's the way it is.

In general, the system time zone is stored in the file /etc/localtime.
You can set it with:

  # cp /usr/share/zoneinfo/Asia/Karachi /etc/localtime 
  # date
  Fri Apr 16 08:55:27 PKT 2004

If you remove it, it defaults to "GMT" (really UTC):

  # rm /etc/localtime
  # date
  Fri Apr 16 03:55:37 GMT 2004

Even then, you can specify the time zone explicitly with the TZ
environment variable:

  # TZ=Asia/Karachi date
  Fri Apr 16 08:55:45 PKT 2004

Greg
--
When replying to this message, please copy the original recipients.
If you don't, I may ignore the reply or reply to the original recipients.
For more information, see http://www.lemis.com/questions.html
Note: I discard all HTML mail unseen.
Finger [EMAIL PROTECTED] for PGP public key.
See complete headers for address and phone numbers.


pgp0.pgp
Description: PGP signature