I'm trying to use $date -u to get UTC time zone. It works fine but how can i set GTM to get a different time zone. For example, how can i complete that command to check GMT+5 or GMT+6 time zone in command line in Linux?
Any idea how can i do it?
You can set the timezone just for the one call to the date command (without changing the timezone that your system is set to) like so:
TZ=Asia/Calcutta date
Note the space before the date command.
Maybe this is the wrong way, but try setting the time zone, then calling date, then unsetting the time zone.
export TZ=Asia/Calcutta
date
unset TZ
There's a small list here of the time zones: Link To Wikipedia.
Related
I want to create a TF-File for storing Unix Time Zone informations out of a TZ-String as define in POSIX 1003.1 section 8.3.
It seems that timezone compiler zic does not cover this.
For a test I created a file "MYZ.txt" compatible to "zic" dealing with a phantasie time zone "MYZ=My Zone" with UTC offset +0:30 (or +1:30 in summer):
#TZ=MYZ-0:30MYSZ,M3.5.0/2,M10.5.0/3
Rule MYsummer min max - Mar lastSun 2:00w 1:00 MYSZ
Rule MYsummer min max - Oct lastSun 3:00w 0 MYZ
Zone MYZ 0:30 MYsummer %s
The commented first line has the same information as the two rules and Zone information below.
zic MYZ.txt -d /tmp does what I want and stores the time zone information into "/tmp/MYZ".
What I like to use is something like calling
export TZ=MYZ-0:30MYSZ,M3.5.0/2,M10.5.0/3
zic -d /tmp
and having the same time zone information in "/tmp/MYZ" like above.
Of corse I could implement a tool creating "MYZ.txt" out of the TZ environment variable.
But I guess somthing similar is avaible within the UNIX/Linux standard tools.
This may be realted to TZ Variable, custom file .
Thanks for any help,
Tom
I need to parameter-ize a datetime value with an objective of passing to a constructed URI to make a Smartsheet API call to get data (i.e. sheets) changed in last 24 hours.
I want to use Linux date command as I can do something like date -d '1 day ago' %F to get the output of a day before today. How can I use the date command to convert the value to yyyy-MM-dd'T'HH:mm:ss'Z' format to get something like 2018-01-01T00:00:00-07:00?
If the value is not in this particular format, then Smartsheet API complains:
HTTP_01 - Error fetching resource. Status: 400 Reason:
Bad Request : { "errorCode" : 1018, "message" : "The value '/home/my/path/to/param_file/Sysdate' was not valid for the parameter modifiedSince.", "refId" : "1xqawd3s94f4y" }
Thanks,
To output date in ISO 8601 format, you'll probably want to use -I[FMT]/--iso-8601[=FMT] option, if your date supports it (GNU/Linux version does). The FMT is basically a resolution, and in your case you'll want to use s for seconds:
$ date -Is
2018-03-09T09:28:14+01:00
The alternative (for POSIX date, including BSD/OSX date) is to explicitly specify the format and output the time in UTC time zone (-u flag):
$ date -u +"%Y-%m-%dT%H:%M:%SZ"
2018-03-09T08:28:14Z
Note the importance of -u and the explicit Z we can append in that case. Without -u, we would need to output the exact time zone in +hh:mm format, but POSIX date provides support only for time zone name output (%Z). GNU date extends the format set with %:z which outputs the numeric time zone, but if already using GNU date, the first approach with -Is is simpler.
When calling date in your shell use the following format
date +"%Y-%m-%dT%H-%M-%SZ"
2018-03-09T07-44-39Z
To be shortest as possible :
date -u +"%FT%TZ" for UTC
date +"%FT%TZ" for locale's time
Use this alias in the bash_profile:
alias utc='date -u +"%Y-%m-%dT%H:%M:%SZ"'
Then, you can run it like:
$ utc
The output will be:
$ 2021-04-15T01:36:31Z
I am trying to display just the time of the last logon of a user.
The goal is to display the time just like
date "+d% %B%t%Y"
would.
I tried:
last -n1 --time-format "+d% %B%t%Y"
but it keeps telling me that it is an unknown time format.
I also tried the ones in the man last examples, none of those formats seem to work. Is there another way of doing this?
The --time-format option only accepts the following options:
--time-format <format> show timestamps in the specified <format>:
notime|short|full|iso
You might have to parse the datetime yourself, for example from ISO format.
I have a date that is stored in variable
myTime=$(date -d "20120101 14:13:12" +'%Y%m%d %H:%M:%S')
and I want to show it in different time zone without exporting the timezone variable. I tried this command:
c=$(TZ=":US/Eastern" date -d "$myTime" +'%Y%m%d %H:%M:%S')
but it doesn't work. can anyone tell me what is my mistake?
Timezones! It's all about timezones.
You want to store the time in your current zone, so you say
TZ=UTC
then="$(date -d '20120101 14:13:12' +'%Y%m%d %H:%M:%S')"
Now you have a date string! But wait, is that date in UTC or US/Eastern? Our zone is set to UTC, but let's look at that value...
echo "$then"
20120101 14:13:12
Funny, I don't see a zone... How can I know it's a time in UTC? Simple answer: you can't! You have to encode the zone in the string, or it's in the current zone.
You can change the zone date uses for the next run:
eastern="$(TZ=US/Eastern date -d "$then" +%Y-%m%dT%H:%M:%S)"
echo "$eastern"
2012-01-01T14:13:12
But wait, isn't that just the same time? Well yes, but now it's Eastern... you just can't tell that, because you didn't print the zone. The input didn't specify the zone so it was read as Eastern and then converted into the output zone, which is Eastern, and written out as Eastern with the zone omitted.
In order to convert between zones you must include the zone in your time string.
GNU date is very nice and will include this for you if you ask:
then="$(TZ=UTC date -d '20120101 14:13:12' --rfc-3339=seconds)"
echo "$then"
2012-01-01 14:13:12+00:00
Now you see your input date/time in your input zone and you know it is in the input zone because +00:00 tells you that.
Now you can go back and try to convert it:
eastern="$(TZ=US/Eastern date -d "$then" --rfc-3339=seconds)"
echo "$eastern"
2012-01-01 09:13:12-05:00
Aha! Now, because you included the zone in your input to -d and you told date to output in a different zone, the time has changed. You can omit the zone in the format for the output at this step, if you really want to:
eastern="$(TZ=US/Eastern date -d "$then" '%Y-%m-%d %H:%M:%S')"
echo "$eastern"
2012-01-01 09:13:12
But you should not omit the zone because later users of the time string won't know what zone it represents.
I have a string of the format
20110724T080000Z
and I want to convert that to local time in a shell script on linux. I thought I simply could give it as input to date, but I don't seem to be able to tell date what format my input date has.
this
date -d "20110724T080000Z" -u
would make date complain
date: invalid date `20110724T080000Z'
Also, what is the format of the form "20110724T080000Z" called? I have had little success trying to google for it.
That's ISO8601 "basic format" for a combined date and time. date does not seem to be able to parse 20110724T080000Z, but if you are prepared to do a few string substitutions it parses 20110724 08:00:00Z correctly.
The date program recognizes yyyy-mm-ddTHH:MM:SS (as well as yyyy-mm-dd HH:MM:SS), so:
a=20110724T080000Z
b=${a:0:4}-${a:4:2}-${a:6:5}:${a:11:2}:${a:13:2}
date +%F_%T -d "${b} +0"
Would print 2011-07-24_12:30:00 in my locale.
its called Zulu time. Its the same as UCT, which used to be referred to as GMT. It's used with the military to specify UCT so there is no confusion on correspondance.
http://en.wikipedia.org/wiki/Date_(Unix)
this command should work according to wikipedia:
date [-u|--utc|--universal] [mmddHHMM[[cc]yy][[.SS]] The only valid option for this form specifies Coordinated Universal Time.
You might try taking advantage of perl:
perl -e 'print scalar localtime(shift), "\n"' 20110724T080000Z
Though u might have to tweak this a little to get it to work correctly. Ok, I don't know exactly why the perl version doesn't do it well, but here is a Ruby version I've tried, though I can't pick the time out well:
ruby -e "require 'date';print Date.strptime('20110724T080000Z','%Y%m%dT%H%M%SZ').ctime"
gives:
Sun Jul 24 00:00:00 2011