工具类-FormatTime
.
#coding:utf-8 from datetime import datetime def get_date_formatted_date(symblo): """ 获取指定格式 :param symblo: :return: """ data = ["%Y","%m","%d"] now = datetime.now() return now.strftime(symblo.join(data)) def now_date(): """ 当前日期 :return: """ now = datetime.now() return now.date() def now_time(): """ 当前时间 :return: """ now = datetime.now() return now.time().strftime("%H:%M:%S") def chinese_date(): """ 当前的中文日期 :return: """ now = datetime.now() now_date = now.strftime("%Y{y}%m{m}%d{d}").format(y='年',m='月', d='日') return now_date def chinese_time(): """ 当前的中文时间 :return:7 """ now = datetime.now() now_date = now.strftime("%H{h}%M{M}%S{s}").format(h='时', M='分', s='秒') return now_date def chinese_date_time(): """ 当前的中文时间与日期 :return: """ now = datetime.now() now_date = now.strftime("%Y{y}%m{m}%d{d} %H{h}%M{M}%S{s}").format(y='年', m='月', d='日', h='时', M='分', s='秒') return now_date if __name__ == '__main__': print(chinese_date()) print(chinese_time()) print(chinese_date_time()) print(now_date()) print(now_time()) print(get_date_formatted_date("-"))