2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python显示当前中文日期_Python--获取当前日期和时间(含中文格式)

python显示当前中文日期_Python--获取当前日期和时间(含中文格式)

时间:2018-10-09 12:10:06

相关推荐

python显示当前中文日期_Python--获取当前日期和时间(含中文格式)

获取当天日期

调用locale函数

调用time函数

def get_current_date(is_chinese=False):

import time

import locale

if not is_chinese :

return time.strftime('%Y-%m-%d')

elif is_chinese:

locale.setlocale(locale.LC_CTYPE, 'chinese')

return time.strftime('%Y年%m月%d日')

#运行结果

#>>> get_current_date(True)

#‘03月19日’

#>>> get_current_date()

#‘-03-19’

获取当前时间

def get_current_time(is_chinese=False):

import time

import locale

if not is_chinese :

return time.strftime('%Y-%m-%d %H:%M:%S')

elif is_chinese:

locale.setlocale(locale.LC_CTYPE, 'chinese')

return time.strftime('%Y年%m月%d日%H时%M分%S秒')

#运行结果

次设定为群#>>> get_current_time()

#‘-03-19 07:09:07’

#>>> get_current_time(True)

#‘03月19日07时09分13秒’

#>>>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。