파이썬 시스템 시간 설정
2018.01.31 19:59
https://stackoverflow.com/questions/12081310/python-module-to-change-system-date-and-time/12292874
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)
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
15 | 윈도우에서 Python Embeddable 사용하기 | 꿈돌이 | 2019.10.01 | 1668 |
14 | pywin32 설치/적용 | 꿈돌이 | 2018.02.21 | 3734 |
13 | Kivy 테마 -> Atlas 사용 | 꿈돌이 | 2018.02.03 | 4617 |
12 | Kivy 예제 | 꿈돌이 | 2018.02.03 | 3683 |
11 | Kivy와 Flask를 Multiprocess로 돌리기 | 꿈돌이 | 2018.02.03 | 4716 |
» | 파이썬 시스템 시간 설정 | 꿈돌이 | 2018.01.31 | 4022 |
9 | Kivy ScreenManager 화면 전환시 진입 및 종료 | 꿈돌이 | 2018.01.31 | 866 |
8 | Kivy kvlang에서 Label 정렬 | 꿈돌이 | 2018.01.31 | 6019 |
7 |
파이썬 Kivy로 그래프 그리기 간단 예제
![]() | 꿈돌이 | 2018.01.29 | 2560 |
6 | 윈도우 파이썬(< 버전 3.6)으로 print 출력시 raw write 오류 | 꿈돌이 | 2018.01.24 | 1400 |
5 | 파이썬으로 시리얼통신을 위한 가변데이터 만들기 | 꿈돌이 | 2018.01.17 | 3234 |
4 |
파이썬 Tk와 pyserial로 시리얼포트 송수신
![]() | 꿈돌이 | 2017.06.09 | 26617 |
3 |
파이썬 Kivy와 pyserial로 시리얼포트 송수신
![]() | 꿈돌이 | 2017.06.09 | 2784 |
2 | 라즈베리파이와 kivy로 작업을 처음 시작할 때 참고 | 꿈돌이 | 2017.06.08 | 1478 |
1 |
파이썬 폴더 변경시 윈도우 환경변수
![]() | 꿈돌이 | 2017.03.23 | 42229 |