0

Using the below code, I can fetch the current date and time in python:

#!/usr/bin/python
import time

now = time.strftime("%c")
print "Current time %s"  % now

This will output:

Current time Mon Oct 24 09:25:17 2016

But, I need to change the system time to Mon Oct 24 11:25:17 2016 i.e. I need to set system date by adding 2 hours to existing time. Need to change the system date to 2 hours from now. (this question has been marked as duplicate, please check the question once)

This needs to be performed for Linux and Solaris hosts.

Please consider me as a python beginner and provide solutions.

Shankar Guru
  • 1,071
  • 2
  • 26
  • 46
  • 1
    Perhaps check out this link on setting timezones: http://stackoverflow.com/questions/1301493/setting-timezone-in-python – NWaters Oct 24 '16 at 16:29
  • I see that the [link](http://stackoverflow.com/questions/13685201/how-to-add-hours-to-current-time-in-python) used to mark this question as duplicate only says on how to add few hours to current date and time, but my query was on how to change the system date so that the current system date is set to 2 hours from now on both linux and solaris. – Shankar Guru Oct 24 '16 at 16:39
  • I'm not aware of any python OS-independent way to set the system date; you're probably going to need to use one of several ways to execute a system command (and run your application as root) – Foon Oct 26 '16 at 11:51

0 Answers0