User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Date in Bash

Tue Dec 08, 2015 8:17 pm

I'm writing a Time script in bash but when I execute the script I don't get the current time :(

Code: Select all

CURRENT_TIME=$(date + "%x %r %Z")
:twisted:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
joan
Posts: 14471
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Date in Bash

Tue Dec 08, 2015 8:28 pm

Perhaps the space after the +.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Date in Bash

Tue Dec 08, 2015 8:45 pm

joan wrote:Perhaps the space after the +.
Thanks it now works :D
:twisted:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

swampdog
Posts: 266
Joined: Fri Dec 04, 2015 11:22 am

Re: Date in Bash

Sat Dec 12, 2015 3:11 am

Never mess with time.

Code: Select all

$ date "+%x %r %Z"
.. is likely what you wanted. Always log UTC (aka GMT time). A good format is..

YYYY-MM-DD-hh:mm:ss:[nano secs or whatever]

..because it is both language and timezone agnostic.

Return to “Other programming languages”