System

python으로 서버 시간 알아내는 방법

Ye0nny 2018. 9. 10. 00:50

response 메시지 헤더에 있는 서버 시간정보 값을 가져온다.



strptime() : 문자열을 날짜/시간으로 변환

mktime() : 일시를 초 단위 시간으로 변환


1
2
3
4
5
6
7
8
9
10
import urllib2
import time
 
date = urllib2.urlopen('http://www.google.com').headers['Date']
print date
 
time = int(time.mktime(time.strptime(date, '%a, %d %b %Y %H:%M:%S %Z')))
print time
 
 
cs