recipe-576546.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
def get_current_SNTP_time(sntp_server=SNTP_SERVER):
    """ Acquires current time in UTC secs from SNTP server. """
    """ Thanks to Simon Foster's "Simple (very) SNTP client" recipe:
    http://code.activestate.com/recipes/117211/ """
    try:
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        data = '\x1b' + 47 * '\0'
        client.sendto(data, (sntp_server, SNTP_PORT))
        data, address = client.recvfrom(1024)
        if data:
            utc_secs = struct.unpack('!12I', data)[10]
            utc_secs -= TIME_1970
            return utc_secs
    except Exception, e:
        print "get_current_SNTP_time failed:", sntp_server
    return None


# ==============================================================================
# OS_set_datetime
# ==============================================================================
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号