I'm trying to make a function to manually change the date/time on a Linux box, using subprocess.call to date --set= on the box. My issue is in trying to find a cleaner/more pythonic way of formatting everything together to go into the call.
The reason I did it this way is because the date command requires --set= followed by a string, and I couldn't figure out a way to do that in proper format within subprocess.call.
I know ideally I should just use ntpd but unfortunately this is my requirement right now. Any help is greatly appreciated.
def set_system_time(year, month, day, hour, minute, second):
"""Set system time, numeric value formatted as 'YYYY-MM-DD HH:MM:SS'"""
datetime = '--set=' + str(year) + '-' + str(month) + '-' + str(day) \
+ ' ' + str(hour) + ':' + str(minute) + ':' + str(second)
subprocess.call(['date', datetime])