MrAClem
Posts: 7
Joined: Wed Apr 29, 2015 4:37 pm

Date in .sh file

Tue Dec 08, 2015 5:04 pm

I am using this code to name files in an .sh file in wheezy for Pi camera .jpg's.

filename=$(date -u +"%Y-%m-%d_%H_%M")_%01d-T2.jpg

These are the output file names.

2015-12-08_16_32_1-T2.jpg
2015-12-08_16_32_2-T2.jpg
2015-12-08_16_52_1-T2.jpg
2015-12-08_16_52_2-T2.jpg
.
.
It is 6 hours off.(I am in Mountain standard)
I suspect the -u is the universal time, but I can't find any thing on changing it on the web.
Am I on the right path?
How can I set to MS time?

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: Date in .sh file

Tue Dec 08, 2015 5:33 pm

Have you set your timezone correctly ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: Date in .sh file

Tue Dec 08, 2015 5:38 pm

If you leave out the "-u", it should "just work". I.e., use your local timezone.
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Date in .sh file

Tue Dec 08, 2015 5:42 pm

Using -u will display the date in UTC (GMT) regardless of your settings and timezone. Why are you using it?

The date command without the -u will show local time

Code: Select all

rpdom@gallifrey1@~$ TZ="MST" date -u +"%Y-%m-%d_%H_%M"
2015-12-08_17_40
rpdom@gallifrey1@~$ TZ="MST" date +"%Y-%m-%d_%H_%M"
2015-12-08_10_40

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: Date in .sh file

Tue Dec 08, 2015 5:49 pm

If their timezone isn't set correctly taking out the "-u" still won't give the desired result !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Date in .sh file

Tue Dec 08, 2015 5:51 pm

PeterO wrote:If their timezone isn't set correctly taking out the "-u" still won't give the desired result !
Agreed, that too.

MrAClem
Posts: 7
Joined: Wed Apr 29, 2015 4:37 pm

Re: Date in .sh file

Thu Dec 17, 2015 6:06 pm

Thank you.

MrAClem
Posts: 7
Joined: Wed Apr 29, 2015 4:37 pm

Re: Date in .sh file

Sun Dec 20, 2015 12:00 am

Thank you all so much.

That was it!
I had set my timezone, so all OK.
The reason it was there is:
I am new to this, and get programs I don't understand, then try to figure out what they do and modify them to my wants.
This was one of those.

How about changing to 12 hr. am/pm? :)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Date in .sh file

Sun Dec 20, 2015 12:06 am

MrAClem wrote:Thank you all so much.

That was it!
I had set my timezone, so all OK.
The reason it was there is:
I am new to this, and get programs I don't understand, then try to figure out what they do and modify them to my wants.
This was one of those.

How about changing to 12 hr. am/pm? :)
Personally I despise am/pm notation, but it can be done:
http://www.cyberciti.biz/faq/linux-unix ... r-display/

Return to “Beginners”