import logging import pytz from dateutil.tz import * import datetime import os # pingcmd = ‘ping -c 5 www.baidu.com‘ cur_path = os.path.split(os.path.realpath(__file__))[0] cur_file = os.path.split(os.path.realpath(__file__))[0] logger = logging.getLogger("logger") def initlog(): tzname = datetime.datetime.now(tzlocal()).tzname() handler2 = logging.FileHandler(filename=os.path.join(cur_path,cur_file.replace(‘.py‘,‘.log‘))) logger.setLevel(logging.DEBUG) handler2.setLevel(logging.DEBUG) if tzname == ‘UTC‘: logging.Formatter.converter = beijing formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s") handler2.setFormatter(formatter) logger.addHandler(handler2) def beijing(sec,what): beijing_time = datetime.datetime.now() + datetime.timedelta(hours=8) return beijing_time.timetuple() tz = pytz.timezone("Asia/Shanghai")
def getts(): return datetime.datetime.now(tz).strftime("%Y.%m.%d %H:%M:%S")
原文地址:https://www.cnblogs.com/yeyong/p/11122167.html
时间: 2024-10-12 02:48:29