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.


busybox date only accepts very specific time formats, not arbitrary ones.

$ busybox date --help
    [-s,--set] TIME Set time to TIME
Recognized TIME formats:
    YYYY-MM-DD hh:mm[:ss]
    'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead

So you'll just have to write it like, date -s 2010.02.17-19:14:32 (or whichever format you prefer).

  • thanks! So there's no way of getting my date's month (for example `'Jan') into the date command? – tzippy Jan 15 at 12:14
  • not unless you provide your own script that translates your arbitrary date format into one understood by busybox date. date can output most formats fine, just doesn't accept them as input when setting date. – frostschutz Jan 15 at 13:24
  • Got it. That's what I'm doing now with a script that returns the month's number when given the 3 digit string. – tzippy Jan 15 at 13:26

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-16-15 09:01:53
busybox date -s "$d"
  • Amazing! (and now I have to find out why this doesn't work with ArchLinux busybox) – frostschutz Jan 16 at 20:19
  • 1
    OK, for whatever reason, ArchLinux busybox does not accept %Z in date -D. Works fine otherwise. – frostschutz Jan 16 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.