Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:27:35+00:00 2026-06-11T00:27:35+00:00

How can I change System Date, Time, Timezone in Python? Is there any module

  • 0

How can I change System Date, Time, Timezone in Python? Is there any module available for this?

  1. I don’t want to execute any system commands
  2. I want one common solution, which should work on both Unix and Windows.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:27:36+00:00Added an answer on June 11, 2026 at 12:27 am
    import sys
    import datetime
    
    time_tuple = ( 2012, # Year
                      9, # Month
                      6, # Day
                      0, # Hour
                     38, # Minute
                      0, # Second
                      0, # Millisecond
                  )
    
    def _win_set_time(time_tuple):
        import pywin32
        # http://timgolden.me.uk/pywin32-docs/win32api__SetSystemTime_meth.html
        # pywin32.SetSystemTime(year, month , dayOfWeek , day , hour , minute , second , millseconds )
        dayOfWeek = datetime.datetime(time_tuple).isocalendar()[2]
        pywin32.SetSystemTime( time_tuple[:2] + (dayOfWeek,) + time_tuple[2:])
    
    
    def _linux_set_time(time_tuple):
        import ctypes
        import ctypes.util
        import time
    
        # /usr/include/linux/time.h:
        #
        # define CLOCK_REALTIME                     0
        CLOCK_REALTIME = 0
    
        # /usr/include/time.h
        #
        # struct timespec
        #  {
        #    __time_t tv_sec;            /* Seconds.  */
        #    long int tv_nsec;           /* Nanoseconds.  */
        #  };
        class timespec(ctypes.Structure):
            _fields_ = [("tv_sec", ctypes.c_long),
                        ("tv_nsec", ctypes.c_long)]
    
        librt = ctypes.CDLL(ctypes.util.find_library("rt"))
    
        ts = timespec()
        ts.tv_sec = int( time.mktime( datetime.datetime( *time_tuple[:6]).timetuple() ) )
        ts.tv_nsec = time_tuple[6] * 1000000 # Millisecond to nanosecond
    
        # http://linux.die.net/man/3/clock_settime
        librt.clock_settime(CLOCK_REALTIME, ctypes.byref(ts))
    
    
    if sys.platform=='linux2':
        _linux_set_time(time_tuple)
    
    elif  sys.platform=='win32':
        _win_set_time(time_tuple)
    

    I don’t have a windows machine so I didn’t test it on windows… But you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I change the local system's date & time programmatically with C#?
I want to use system's date/time which is in mm/dd/yy format in code. But
I'm making a system called NCIV in PHP. In that system you can change
I want to monitor the windows system tray for icon text changes. How can
How i can change the color with gradient??? I have this now,but is different
How can we trigger a mysql trigger when the system date is changed? Let's
im using this function time() in php im doing echo date(c,time()); however its not
I am getting the Unable to convert MySQL date/time value to System.DateTime error because
Is there a way to get notification of date change in c#? I have
I'd like to get notified when Windows system date/time is changed in my C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.