pyefun.核心支持库.日期时间操作 module

提示

日期时间操作 符合中国人思维逻辑的日期时间操作实用函数

代码示例
 1import unittest
 2
 3from .日期时间操作 import *
 4
 5
 6class Test日期时间操作(unittest.TestCase):
 7
 8    def test_1(self):
 9        pass
10        t = 取现行时间()
11        print(t)
12        print(t.到文本("YYYY年MM月DD日 HH时mm分ss秒"))
13        print(t.到文本())
14        print("取年", t.取年())
15        print("取月", t.取月())
16        print("取日", t.取日())
17        print("取小时", t.取小时())
18        print("取分钟", t.取分钟())
19        print("取秒", t.取秒())
20        print("取微妙", t.取微妙())
21        print("取每周的第几天", t.取每周的第几天())
22        print("取每年的第几周", t.取每年的第几周())
23        print("取每年的第几天", t.取每年的第几天())
24        print("取每月的第几周", t.取每月的第几周())
25        print("取日期", t.取日期())
26        t.设置年月日(2020, 1, 1)
27        print(t.到文本())
28        t.设置时分秒(1, 1, 1)
29        print(t.到文本())
30        t = t.增减日期时间(
31            years=1,
32            months=1,
33            days=1,
34            hours=1,
35            minutes=1,
36            seconds=1,
37        )
38        print("增减日期时间", t.到文本())
39
40        t1 = 取现行时间()
41        t2 = t1.copy()
42        print("取现行时间", t1.到文本())
43        t2 = t2.增减日期时间(
44            years=1,
45            months=1,
46            days=1,
47            hours=1,
48            minutes=1,
49            seconds=1,
50        ).datetime()
51        print("t2", t2)
52        print("t1", t1)
53        print("取时间间隔", t1.取时间间隔(t2))
54
55        t2 = 取现行时间()
56        t2 = t2.增减日期时间(
57            years=-1,
58            months=1,
59            days=1,
60            hours=1,
61            minutes=1,
62            seconds=1,
63        )
64        print("取友好时间", t2.取友好时间())
65
66        t = 取现行时间().取时间戳()
67        print(t)
68
69
70
71        t = 日期时间("2021-05-17 12:01:42").取时间戳()
72        print(t)
73
74        t = 日期到时间戳("2021-05-17 12:01:42")
75        print(t)
76
77    def test_2(self):
78        list = 时间迭代("2021-01-17", "2021-05-27")
79        for i in list.range('months'):
80            print(i.to_datetime_string())
81
82        # for i in list.range('days'):
83        #     print(i.to_datetime_string())
84
85    def test_3(self):
86        data = date("Y-m-d H:i:s", now().取时间戳())
87        print(data)
88    def test_4(self):
89        print(取现行时间2('%d %H:%M:%S',True))
90
91    def test_5(self):
92        t = 日期时间(取现行时间戳())
93        print(t)
94        print(t.取时间戳())
pyefun.核心支持库.日期时间操作.date(format, timestr='now')[源代码]
pyefun.核心支持库.日期时间操作.now()[源代码]
pyefun.核心支持库.日期时间操作.创建日期时间(timestr)[源代码]
pyefun.核心支持库.日期时间操作.取现行时间()[源代码]
pyefun.核心支持库.日期时间操作.取现行时间2(格式, 自定义=False)[源代码]

自定义 %Y-%m-%d %H:%M:%S (yyyy-MM-dd HH:mm:ss)这种格式不可以 格式1 = 2020-10-09 22:11:52 格式2 = 2020-10-09 格式3= 22:13:37 格式4= 2020年10月17日18时27分40秒

%a # 本地(local) 简化星期名称 %A # 本地完整星期名称 %b # 本地简化月份名称 %B # 本地完整月份名称 %c # 本地相应的日期和时间表示 %d # 一个月中的第几天(01-31) %H # 一天中的第几个小时(24小时制00-23) %I # 第几个小时(12小时制01-12) %j # 一年中的第几天(001-366) %m # 月份(01-12) %M # 分钟数(00-59) %p # 本地am或pm的相应符 %S # 秒(01-60) %U # 一年中的星期数。(00-53 星期天是一个星期的开始)第一个星期天之前的所有天数都放在第0周 %w # 一个星期中的第几天(0-6 0是星期天) %W # 和%U基本相同,不同的是%W以星期一为一个星期的开始 %x # 本地相应日期 %X # 本地相应时间 %y # 去掉世纪的年份(00-99) %Y # 完整的年份 %z # 时区的名字

pyefun.核心支持库.日期时间操作.取现行时间戳()[源代码]
pyefun.核心支持库.日期时间操作.日期到时间戳(str='now')[源代码]
class pyefun.核心支持库.日期时间操作.日期时间(str='now')[源代码]

基类:object

copy()[源代码]
datetime()[源代码]
t

:py:class:`pendulum.datetime.DateTime`的别名

到文本(format='YYYY-MM-DD HH:mm:ss')[源代码]
取分钟()[源代码]
取友好时间()[源代码]
取小时()[源代码]
取年()[源代码]
取微妙()[源代码]
取日()[源代码]
取日期()[源代码]
取时间戳()[源代码]
取时间间隔(datetime)[源代码]
取月()[源代码]
取月天数()[源代码]
取每周的第几天()[源代码]
取每年的第几周()[源代码]
取每年的第几天()[源代码]
取每月的第几周()[源代码]
取秒()[源代码]
增减日期时间(years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0)[源代码]
设置年月日(year=None, month=None, day=None)[源代码]
设置时分秒(hour=0, minute=0, second=0)[源代码]
pyefun.核心支持库.日期时间操作.时间_设置语言包(名称='zh')[源代码]
pyefun.核心支持库.日期时间操作.时间迭代(start, end)[源代码]

为支持单位range()有:years,months,weeks, days,hours,minutes和seconds for i in list.range(‘months’):

print(i.to_datetime_string())