Date command in busybox not accepting formatted input date

busyboxdate

I want to set the date using busybox's date command (BusyBox v1.21.0).
My custom date to which I want to set the computer is of this form:

Tue, 15 Jan 2019 10:46:13 GMT

What my date command is capable of is to print out the date in the same format using this string:

date +"%a, %d %b %Y %T %Z"

It returns the date in the exact same format as above.
But It would not accept this when I use the -s option to set the date.

This fails for example:

date -u +"%a, %d %b %Y %T %Z" -s "Wed, 17 Feb 2010 19:14:32 UTC"
date: invalid date 'Wed, 17 Feb 2010 19:14:32 UTC'

I know busybox commands are reduced in function, but I imagined that when it can handle the format string to print the current date in the desired form, then it should also be able to use it to interpret an input string.

Best Answer

You can get busybox date to do the conversion of formats for you, using -D to specify the input format, and the usual +... for the output format, with -d providing the reference date and time. For example,

r='Tue, 15 Jan 2019 09:16:53 GMT'
d=$(busybox date -d "$r" -D "%a, %d %b %Y %T %Z" +'%Y-%m-%d %H:%M:%S')
# d becomes 2019-01-15 09:01:53
busybox date -s "$d"
Related Question