栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python版的迷你程序——年月日时分秒

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python版的迷你程序——年月日时分秒

        这些个小东西对于文件的记录,log的输出等还是很有用的,先获取了再说:

# -*- coding: utf-8 -*-

import calendar
import datetime


"""
%y 2个数字表示年份
%Y 4个数字表示年份
%b 月份的简写。一月:Jan
%B 月份的全写。一月:January
%m 月份[01,12]
%d 日在这个月中的天数(这个月的第几天)
%H 24小时制
%h 12小时制
%M 分钟[00,59]
%S 秒[00,61]

%f 微秒

%a 星期的简写。星期一 : Mon
%A 星期的全写。星期一 :Monday

%c 日期时间的字符串表示。'Mon Jan 14 00:00:00 2019'
%x 日期字符串
%X 时间字符串

%j 日在年中的天数[001,366]
%U 在当年的第几周,星期天作为周的第一天
%w 今天在这周的第几天[0,6],6表示星期天
%W 是当年的第几周,星期一作为周的第一天
"""

# 显示日历 2021年11月份 
print("total %d days" % calendar.monthrange(2021,11)[1])
print(calendar.month(2021,11))

# 显示昨天 今天 明天
today     = datetime.date.today() 
deltadays = datetime.timedelta(days=1) 
yesterday = today-deltadays 
tomorrow  = today+deltadays 
print(yesterday)
print(today)
print(tomorrow)


now = datetime.datetime.now()
print(now)
otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S")
print(otherStyleTime)
otherStyleTime = now.strftime("%Y-%b-%d %H:%M:%S")
print(otherStyleTime)
otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S.%f")
print(otherStyleTime)
otherStyleTime = now.strftime("%x")
print(otherStyleTime)
otherStyleTime = now.strftime("%X")
print(otherStyleTime)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/499010.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号