LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-05-2016, 11:26 AM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Question Show date and time in a chosen timezone?


I have access to a Debian server, but not as root (so the solution I aim for should work for normal users without su or sudo steps).

I have a shell function which eventually prints the date and time with:

Code:
date '+%F %T %:z'
# Result is like: 2016-09-05 18:21:38 +02:00
# I wanted it to be the same, but in my timezone:
# 2016-09-05 13:21:38 -03:00
My shell prompt in Bash also display the clock with seconds: PS1="[...] \t [...]". The prompt is like:

Code:
18:36:16 me@server:~/some/folder/tmp
$
The problem is that me and the server are in different timezones. I want to see its clock, in both cases, in my timezone (so I can easily think about times here and/or there and so on).

The 'date' command does not seem to have an option for this. The shell prompt too?

Is it possible to solve both? What can I do?

Last edited by dedec0; 09-05-2016 at 11:42 AM.
 
Old 09-05-2016, 12:36 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
You can use the TZ environment variable i.e.

TZ='America/Los_Angeles' date '+%F %T %:z' (Replace America/Los_Angles with the servers real timezone)

You can create a script function etc. to display the servers time easily.

Just as a side note the way the world communicates time is via UTC. Servers should keep there time in UTC...
 
1 members found this post helpful.
Old 09-06-2016, 05:37 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
export TZ in ~/.bashrc for regular TZ display, or in bash (may work in a script locally. May need export. Test)
Code:
TZ='America/Los_Angeles' ; date
 
1 members found this post helpful.
Old 09-06-2016, 07:22 AM   #4
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
It needed export to work (server is not in LA timezone):

Code:
14:16:44 me@there:~
$ TZ='America/Los_Angeles' ; date
Tue Sep  6 14:16:53 CEST 2016
14:16:53 me@there:~
$ export TZ='America/Los_Angeles' ; date
Tue Sep  6 05:17:20 PDT 2016
05:17:20 me@there:~
$ export TZ='America/Sao_Paulo' ; date
Tue Sep  6 09:17:35 BRT 2016
09:17:35 me@there:~
$ # :D :D :D right there!

I will add added this line to my bashrc:

Code:
# Data e hora vistas no fuso horário correto (meu fuso)
export TZ='America/Sao_Paulo'
Works beautifully. Thank you both! ^,^

Last edited by dedec0; 09-06-2016 at 07:33 AM.
 
Old 09-06-2016, 12:13 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad it worked out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CentOS 7 Date/TimeZone Issue nishith Linux - Server 5 08-02-2016 08:06 AM
how do I show date in daylight savings time not utc Glenn D. Programming 2 11-21-2009 06:55 AM
Change timezone using date davholla Linux - General 16 11-09-2005 02:53 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration