This technique should be similar or the same as on Ubuntu; though the following code does not work on the router. One method is the following:
dateFromServer=$(curl -v --silent https://google.com/ 2>&1 \
| grep Date | sed -e 's/< Date: //')
date +"%d%m%Y%H%M%S" -d "$dateFromServer"
The result is
'ate: invalid date 'Sat, 12 May 2018 18:49:18 GMT
or Get the date from a HTTP response header. Remove clutter. Set the date.
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
The results I get are as follows:
@Heyzeus:/tmp/home/root# date -s `curl -I 'https://google.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'` BusyBox v1.25.1 (2018-05-06 13:19:15 EDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string SPEC='date' (default) for date only, 'hours', 'minutes', or 'seconds' for date and time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats: hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] 'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Another
date -s "$(wget -qSO- --max-redirect=0 startpage.com 2>&1 | grep Date: | cut -d' ' -f5-8)"
results in: date: invalid date '13 May 2018 22:46:44'
The time extrated the first two results is for example: "Sat, 12 May 2018 18:49:18 GMT" and date -s requires something more like 2018-05-12 18:49:18 Or as listed under "recognized time formats."
Its close. But "Sat," needs to be removed, month needs replacing with a number, and then arranged properly; If this could be done exclusively in a single terminal command that would be great.
date -s requires something more like 2018-05-12 2018 18:49:18
– Tyler May 13 '18 at 22:47