LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2017, 02:26 PM   #1
wBB
LQ Newbie
 
Registered: Jan 2017
Posts: 25

Rep: Reputation: Disabled
System date and time + timezone with DATE command


Hi!
I'm looking at the "man Date" but I can't understand the syntax.
My system timezone is correct, at -0300. When I run the "Date" command for a given value, the timezone changes.

QUESTION: how do I adjust the date and time in this example:
February 1, 2010, at time of 13hours 14minutes 15seconds, with timezone at -0300

I am running this command and it is displaying an invalid date error:
date +%Y%m%d%H%M%S%z -s "20100201131415-0300"
 
Old 07-28-2017, 02:52 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
When you run date with the -s option, you are changing the system date.
If that's what you want to do, your command should be something like
Code:
date -s "2010-02-01 13:14:15 -0300"
(But I shudder to think what happens to your system if you change the date to be more than 7 years ago...)
use
Code:
date -d "<string>"
to experiment without changing the system date
For more details on how to format the date string see:
Code:
info date
 
Old 07-28-2017, 03:01 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You can do it like this:
Code:
$ date -s "01 FEB 2010 13:14:15-03:00"
Well ... I KNOW that it works sans the time zone term, I just never used the time zone in this command since the time zone is already all set in my system, or I can change it also using /etc/timezone

EDIT: I see scasey's response and perhaps there should be that space before the timezone. As I say, never did anything with the timezone in this command.
 
Old 07-28-2017, 03:13 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Quote:
Originally Posted by rtmistler View Post
You can do it like this:
Code:
$ date -s "01 FEB 2010 13:14:15-03:00"
Well ... I KNOW that it works sans the time zone term, I just never used the time zone in this command since the time zone is already all set in my system, or I can change it also using /etc/timezone

EDIT: I see scasey's response and perhaps there should be that space before the timezone. As I say, never did anything with the timezone in this command.
info date says to set the TZ environment variable, then execute date. When I execute the command I posted (with -d, not -s), it doesn't change the timezone from my -0700 (MST) to -0300. I've never needed to use the time zone in the date command, either.

One online reference says: The --date=STRING is a mostly free format human readable date string
such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or
even "next Thursday".

Last edited by scasey; 07-28-2017 at 03:15 PM.
 
Old 07-28-2017, 03:18 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I have to admit it's one of those commands you keep banging away with, changing it, until you get it right.

Meanwhile another part of that is just to web search for "linux date examples" and you'll see a bunch.
 
Old 07-28-2017, 04:15 PM   #6
wBB
LQ Newbie
 
Registered: Jan 2017
Posts: 25

Original Poster
Rep: Reputation: Disabled
First of all: the "date" command is very confusing!!

Quote:
But I shudder to think what happens to your system if you change the date to be more than 7 years ago...
There was no problem with the system. It was just an example ...

The below command works partially because it didn't change the system timezone, but it works to change date and time. With the "-d" option also worked partially.
Code:
date -s "2010-02-01 13:14:15 -0300"
Regarding the timezone problem, I understood what is happening at this moment. In this case the system identified as daylight saving time in the place where I live. I don't know how to fix it, but I don't think it'll make any difference where I'm going to use it.

Thank you!!
 
Old 07-28-2017, 04:16 PM   #7
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
If you have it available, the timedatectl utility makes date/time/timezone configuration pretty foolproof.
 
Old 07-28-2017, 05:00 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
without changing the clock on the system, you can utilize "export TZ=<zone> ; date" maneuvers

Code:
date ; export TZ=America/Los_Angeles; date
Fri Jul 28 18:01:57 EDT 2017
Fri Jul 28 15:01:57 PDT 2017
Have fun!
Timezone "math". ouch.

Last edited by Habitual; 07-28-2017 at 05:03 PM.
 
Old 07-28-2017, 06:41 PM   #9
wBB
LQ Newbie
 
Registered: Jan 2017
Posts: 25

Original Poster
Rep: Reputation: Disabled
I'm building a small program in NodeJS to fix the system date and time and for this I use the "exec" function from "child_process" of the Node. If it has a way to run in bash as well, it might work fine. So I'm using the "date" command.
 
Old 07-28-2017, 08:30 PM   #10
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,272
Blog Entries: 28

Rep: Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124
There's a neat little command line utility called "tzselect" that you can use to set the time zone. It quite easy to use and many distros include it out of the box.

What works for me is to use the date command to set the time, then use the hwclock to set the hardware clock fomr the system time.
 
Old 07-29-2017, 09:27 AM   #11
wBB
LQ Newbie
 
Registered: Jan 2017
Posts: 25

Original Poster
Rep: Reputation: Disabled
frankbell, I didn't know this command "tzselect", so I've used "timedatectl" instead. But "tzselect" is also good to do what I need.
thanks!
 
  


Reply

Tags
date, timezone


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Show date and time in a chosen timezone? dedec0 Linux - Server 4 09-06-2016 12:13 PM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 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 - Newbie

All times are GMT -5. The time now is 05:48 AM.

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