I'm trying to work with a curl request and the following string:
?created_from={FROM_TIMESTAMP}&created_to={TO_TIMESTAMP}
I've been working with the documentation quite a bit, so I know that brackets are not needed. Unfortunately, the only information I have is to us "Gregorian Timestamp" which I haven't found a lot of documentation on.
I have tried a number of different combinations. Using timestamps for 10-01-2018 to 10-02-18. Here's what I've tried:
?created_from=2019-02-01T00:00:00&created_to=2019-02-02T00:00:00)
This just returns logs from the past 30 days, not the specified date range.
Then I tried:
?created_from=1538352000&created_to=1538438400
This returns the following error message: "message":"created_to 63718254228 is more than 2682000 seconds from created_from 1538352000","cause":63718254228 which doesn't make sense to me because the created_from is 1538352000 not 63718254228.
I have also tried a bunch of other syntax and combinations of formats like the following:
?created_from=2018-10-29T00:00:00Z&created_to=2018-11-01T00:00:00Z
And many other tries. Does anyone know how to properly write a Gregorian timestamp in a curl variable request? I've searched everywhere.
Gregorian timestamps have an epoch date of 0-01-01 00:00:00 as opposed to the standard UNIX epoch of 1970-01-01 00:00:00, which as a Gregorian timestamp is 62167219200.
So, you can simply add that to a UNIX timestamp to get the Gregorian value.
For example, consider the datetime 02/24/2019 # 10:17pm (UTC), its UNIX timestamp is 1551046620. To obtain its Gregorian counterpart:
1551046620 + 62167219200 = 63718265820
Related
When date was 2018-03-21 19:40, i tried following code
var date = new Date();
console.log(date);
Output :
2018-03-21T16:40:53.755Z
Server is missing for 3 hours as you see. I fixed it by adding 3 hours but I think it's not a good way. How can i fix this problem with better way ?
I don't think the date is incorrect, if you look closely at the format it is being printed, it has a Z at the end, which means:
A suffix which, when applied to a time, denotes a UTC offset of 00:00;
often spoken "Zulu" from the ICAO phonetic alphabet representation of
the letter "Z".
I guess you are in a place separated by 3 hours from UTC.
Node.js uses this format to print Date objects by default, but you can print your local time using toLocaleString():
console.log(date.toLocaleString());
Your server is most likely in another time zone.
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 have a date in a the %c format (could be any other) and I need to use it in the date command. %c is NOT the American format. It is the German one because it's a German server. This also did not work properly on an American server. (Locales set to German or American)
This does not work (error included):
user#server:~$ NOW=$(date +%c); echo $NOW
Do 19 Dez 2013 22:33:28 CET
user#server:~$ date --date="$NOW" +%d/%m/%Y
date: ungültiges Datum „Do 19 Dez 2013 22:33:28 CET“
(date: ungültiges Datum „Do 19 Dez 2013 22:33:28 CET“ = date: invalid date „Do 19 Dez 2013 22:33:28 CET“)
The difficulty is that I don't know which locale or even whci dateformat will be used later since the user can set their own format. So a simple specific parsing solution ist not really going to work!
But how do I do it?
To gerneralize the issue:
If I have a date format format1 (which could be any or at least one that can be reversed) I can use date to get a formatted date. But if I want to format it to another date (format2) how do I do it?
Any solution using anything else than the coreutils is pointless since I am trying to develop a bash script for as many unix machines as possible.
DATE=$(date "+$format1")
date --date="$DATE" "+$format2" # Error in most cases!
This is needed because I have a command which the user can give a date format. This date string is going to be displayed. But in a later step I need to convert this date string into another fixed one. I can manipulate the whcih format the command will get and I can maniplulate the output (or what the user will see).
I cannot run the command twice because it is very time consuming.
Update:
I have found something like a solution:
# Modify $user_format so it can be parsed later
user_format="$user_format %s"
# Time consuming command which will print a date in the given format
output=$(time_consuming_command params "$user_format" more params)
# This will only display what $user_format used to be
echo ${output% *}
# A simple unix timestamp parsing ("${output##* }" will only return the timestamp)
new_formated_date=$(date -d "1970-01-01 ${output##* } sec UTC" "+$new_format")
This is working and might be helpful to others. So I will share this with you.
Not possible with --date as of GNU coreutils 8.22. From the date manual:
‘-d datestr’
‘--date=datestr’
Display the date and time specified in datestr instead of the current
date and time. datestr can be in almost any common format. It can
contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For
example, --date="2004-02-27 14:19:13.489392193 +0530" specifies the
instant of time that is 489,392,193 nanoseconds after February 27,
2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east
of UTC.
Note: input currently must be in locale independent format. E.g., the
LC_TIME=C below is needed to print back the correct date in many
locales:
date -d "$(LC_TIME=C date)"
http://www.gnu.org/software/coreutils/manual/html_node/Options-for-date.html#Options-for-date
Note it says that the input format cannot be in a locale-specific format.
There may be other libraries or programs that would recognize more date formats, but for a given date format it would not be difficult to write a short program to convert it to something date recognizes (for example, with Perl or awk).
Why don't you store the time as unixtime (ie milliseconds since 1st of january 1970) Like 1388198714?
The requested exercise in trying to parse all date formats from all around the world as a one shot bash script without reasonable dependecies is slightly ridiculous.
You may use libdatetime-format-flexible-perl.
#!/usr/bin/perl
use DateTime::Format::Flexible;
my $date_str = "So 22 Dez 2013 07:29:35 CET";
$parser = DateTime::Format::Flexible->new;
my $date = $parser->parse_datetime($date_str);
print $date
Default output will be 2013-12-22T07:29:35, but since $date is not a regular string but object, you can do something like this:
printf '%02d.%02d.%d', $date->day, $date->month, $date->year;
Also date behavior probably should be considered as a bug. I think so, because date in the same format but in russian is parsed correctly.
$ export LC_TIME=ru_RU.UTF-8
$ NOW="$(date "+%c")"
$ date --date="$NOW" '+%d.%m.%Y'
22.12.2013
If you meant the formatting is wrong, I think what you want is:
NOW=$(date +%c)
date --date="$NOW" +%d/%m/%Y
note the lowercase %d and %m.
Locally, this is what I get:
root#server2:~# NOW=$(date +%c)
root#server2:~# date --date="$NOW" +%d/%m/%Y
19/12/2013
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 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