Skip to content

Instantly share code, notes, and snippets.

@taojy123
Created February 8, 2015 02:44
Show Gist options
  • Save taojy123/f9e490e24796dfc4aac6 to your computer and use it in GitHub Desktop.
Save taojy123/f9e490e24796dfc4aac6 to your computer and use it in GitHub Desktop.
通过互联网获取当前时间
import urllib2
import re
import time
def get_online_seconds():
p = urllib2.urlopen("http://www.baidu.com/").read()
r = re.findall(r'serverTime : "(.*?)"', p)
if r:
t = r[0]
else:
t = 0
return int(t)
t = get_online_seconds()
print t
print time.ctime(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment