1

I need to set date and time .Tried using os.system('date -s %s' % date_str) with date_str as '2020-04-29 00:55:06' from my busy box but every time I get :

BusyBox v1.28.4 () 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
        -k              Set Kernel timezone from localtime and exit

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]

but if I use the same date_str directly as **date -s '2025-05-03 10:55:06'** it works. why is it so?

PDB
  • 11
  • 1
  • 2
    To follow what you've written in manually, shouldn't the string-formatting be this instead? `os.system("date -s '%s'" % date_str)` – Hampus Larsson May 04 '20 at 09:43
  • ^This. OP, your formatting doesn't include quotes for the parameter. – h4z3 May 04 '20 at 09:45
  • Please to refer the Reference [Website](https://stackoverflow.com/questions/12081310/python-module-to-change-system-date-and-time) – Uday May 04 '20 at 09:47
  • 1
    @HampusLarsson Thanks! I don't know how I overlooked this silly thing!! – PDB May 04 '20 at 09:55

0 Answers0