工具类-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("-"))

 

posted @ 2018-09-21 14:34  SneakingSled  阅读(830)  评论(0编辑  收藏  举报