LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-22-2018, 03:54 AM   #1
gilesaj001
Member
 
Registered: Apr 2017
Location: Australia
Distribution: Ubuntu
Posts: 79

Rep: Reputation: 0
Chage the date in a script to use another time zone


I have a server that I have a web cam on and the server is set to Ottawa Canada time.

I have a new webcam that I want to run from the same server in Ottawa but the Image will be from Australia. My problem is as follows:

I have 'date' functions in the script to add dates to the image and also used in the script. They all work fine for the Ottawa image as 'date' is Ottawa Canada but I need a way to run the Australian scripts in that timezone on the server using Ottawa time.

I am not a programmer so the code is probably really bad but it works for Ottawa. I tried to add this line but that did not zone for 'date'
Quote:
date=$(TZ=Australia/Canberra date '+%Y-%m-%d %H:%M')
An example is as follows:

Quote:
THISMONTH=$(date +%B)
THISDAY=$(date +%d)
LASTMONTH=$(date -d "-1 month" +%B)
THISYEAR=$(date +%Y)
LASTYEAR=$(date -d "-12 month" +%Y)
LASTNUM=$(date -d "-1 month" +%m)

echo $THISYEAR
echo $LASTYEAR
if [[ $THISDAY = "02" ]]
then
echo "This must be the second"
echo 0 > /home/www/localhost/htdocs/scripts/merimbula/webcam_counter_avi
echo "reset webcam_counter_avi to 0"
fi
if [[ $THISMONTH = "January" && $THISDAY = "01" ]]
then
echo "This must be 01 January"
THISYEAR=$LASTYEAR
fi
Any help would be appreciated.
 
Old 10-22-2018, 04:14 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I am not quite sure what you mean by "that did not zone for 'date'". Do you want to see the time zone in the output? In this case, add %Z.

It works for me (Fedora 28, Centos 7, Raspbian):
Code:
$ date=$(TZ=Australia/Canberra date '+%Y-%m-%d %H:%M %Z')
$ echo $date
2018-10-22 20:13 AEDT
$ date
Mon Oct 22 18:10:13 JST 2018
 
Old 10-22-2018, 04:15 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Looks ok, and works here. Perhaps you should expand further on " did not zone for 'date'".
 
Old 10-22-2018, 04:49 AM   #4
gilesaj001
Member
 
Registered: Apr 2017
Location: Australia
Distribution: Ubuntu
Posts: 79

Original Poster
Rep: Reputation: 0
OK I guess I was staring at the problem too long because the script I was running to do the test had the date stated as

Quote:
DATE=$(TZ=Australia/Canberra date '+%Y-%m-%d %H:%M')
It is working fine thanks for the clarity.
 
  


Reply

Tags
bash function, datetime



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash shell - date: invalid date -d for string in another time zone OracleDBA88 Linux - Software 3 06-07-2018 02:13 AM
[SOLVED] can I just display the time without the time zone, date and day lubuntu 14.10 desktop mikeprosceo Linux - Desktop 2 03-16-2015 06:01 PM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
Can't chage the time zone from PDT to IST!! pls help. joykiranr Linux - Desktop 4 07-29-2009 02:40 AM
Cannot set time/date to other time zone than UTC (Kubuntu) jamangold Ubuntu 1 12-23-2005 05:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:25 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