1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python中年月日_Python中当前年和月的日期时间

python中年月日_Python中当前年和月的日期时间

时间:2022-01-15 16:32:54

相关推荐

python中年月日_Python中当前年和月的日期时间

使用:from datetime import datetime

current_month = datetime.now().strftime('%m') // 02 //This is 0 padded

current_month_text = datetime.now().strftime('%h') // Feb

current_month_text = datetime.now().strftime('%B') // February

current_day = datetime.now().strftime('%d') // 23 //This is also padded

current_day_text = datetime.now().strftime('%a') // Fri

current_day_full_text = datetime.now().strftime('%A') // Friday

current_weekday_day_of_today = datetime.now().strftime('%w') //5 Where 0 is Sunday and 6 is Saturday.

current_year_full = datetime.now().strftime('%Y') //

current_year_short = datetime.now().strftime('%y') // 18 without century

current_second= datetime.now().strftime('%S') //53

current_minute = datetime.now().strftime('%M') //38

current_hour = datetime.now().strftime('%H') //16 like 4pm

current_hour = datetime.now().strftime('%I') // 04 pm

current_hour_am_pm = datetime.now().strftime('%p') // 4 pm

current_microseconds = datetime.now().strftime('%f') // 623596 Rarely we need.

current_timzone = datetime.now().strftime('%Z') // UTC, EST, CST etc. (empty string if the object is naive).

以上内容对于任何日期解析都是有用的,不仅是现在或今天。它可以用于任何日期分析。e.g.

my_date = "23-02- 00:00:00"

datetime.strptime(str(my_date),'%d-%m-%Y %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S+00:00')

datetime.strptime(str(my_date),'%d-%m-%Y %H:%M:%S').strftime('%m')

等等。。。

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