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)

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

clyfk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值