


既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
| function | Description |
|---|---|
| time() | 返回自epoch以来经过的秒数 |
| ctime() | 以经过的秒数作为参数,返回当前日期和时间 |
| sleep() | 在给定的持续时间内停止线程的执行 |
| time.struct_time Class | 函数要么将此类作为参数,要么将其作为输出返回 |
| localtime() | 以自epoch以来经过的秒数作为参数,并以时间形式返回日期和时间。struct_time格式 |
| gmtime() | 与localtime()类似,返回时间。UTC格式的struct_time |
| mktime() | ocaltime()的倒数。获取包含9个参数的元组,并返回自epoch pas输出以来经过的秒数 |
| asctime() | 获取包含9个参数的元组,并返回表示相同参数的字符串 |
| strftime() | 获取包含9个参数的元组,并根据使用的格式代码返回表示相同参数的字符串 |
| strptime() | 分析字符串并及时返回。struct_time格式 |
代码格式化:
在用示例解释每个函数之前,先看一下所有合法的格式化代码的方式:
| Code | Description | Example |
|---|---|---|
| %a | Weekday (short version) | Mon |
| %A | Weekday (full version) | Monday |
| %b | Month (short version) | Aug |
| %B | Month (full version) | August |
| %c | Local date and time version | Tue Aug 23 1:31:40 2019 |
| %d | Depicts the day of the month (01-31) | 07 |
| %f | Microseconds | 000000-999999 |
| %H | Hour (00-23) | 15 |
| %I | Hour (00-11) | 3 |
| %j | Day of the year | 235 |
| %m | Month Number (01-12) | 07 |
| %M | Minutes (00-59) | 44 |
| %p | AM / PM | AM |
| %S | Seconds (00-59) | 23 |
| %U | Week number of the year starting from Sunday (00-53) | 12 |
| %w | Weekday number of the week | Monday (1) |
| %W | Week number of the year starting from Monday (00-53) | 34 |
| %x | Local date | 06/07/22 |
| %X | Local time | 12:30:45 |
| %y | Year (short version) | 22 |
| %Y | Year (full version) | 2022 |
| %z | UTC offset | +0100 |
| %Z | Timezone | CST |
| %% | % Character | % |
struct_time 类具有以下属性:
| Attribute | Value |
|---|---|
| tm_year | 0000, …, 2019, …, 9999 |
| tm_mon | 1-12 |
| tm_mday | 1-31 |
| tm_hour | 0-23 |
| tm_min | 0-59 |
| tm_sec | 0-61 |
| tm_wday | 0-6 (Monday is 0) |
| tm_yday | 1-366 |
| tm_isdst | 0, 1, -1 (daylight savings time, -1 when unknown) |
现在让我们看几个 time 模块的例子
使用time模块查找日期和时间
使用上表中描述的内置函数和格式化代码,可以在 Python 中轻松获取日期和时间。
import time
#time
a=time.time() #total seconds since epoch
print("Seconds since epoch :",a,end='n----------n')
#ctime
print("Current date and time:")
print(time.ctime(a),end='n----------n')
#sleep
time.sleep(1) #execution will be delayed by one second
#localtime
print("Local time :")
print(time.localtime(a),end='n----------n')
#gmtime
print("Local time in UTC format :")
print(time.gmtime(a),end='n-----------n')
#mktime
b=(2019,8,6,10,40,34,1,218,0)
print("Current Time in seconds :")
print( time.mktime(b),end='n----------n')
#asctime
print("Current Time in local format :")
print( time.asctime(b),end='n----------n')
#strftime
c = time.localtime() # get struct\_time
d = time.strftime("%m/%d/%Y, %H:%M:%S", c)
print("String representing date and time:")
print(d,end='n----------n')
#strptime
print("time.strptime parses string and returns it in struct\_time format :n")
e = "06 AUGUST, 2019"
f = time.strptime(e, "%d %B, %Y")
print(f)
Output:
Seconds since epoch : 1565070251.7134922
———-
Current date and time:
Tue Aug 6 11:14:11 2019
———-
Local time :
time.struct_time(tm_year=2019, tm_mon=8, tm_mday=6, tm_hour=11, tm_min=14, tm_sec=11, tm_wday=1, tm_yday=218, tm_isdst=0)
———-
Local time in UTC format :
time.struct_time(tm_year=2019, tm_mon=8, tm_mday=6, tm_hour=5, tm_min=44, tm_sec=11, tm_wday=1, tm_yday=218, tm_isdst=0)
———–
Current Time in seconds :
1565068234.0
———-
Current Time in local format :
Tue Aug 6 10:40:34 2019
———-
String representing date and time:
08/06/2019, 11:14:12
———-
time.strptime parses string and returns it in struct_time format :
time.struct_time(tm_year=2019, tm_mon=8, tm_mday=6, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=218, tm_isdst=-1)
datetime 模块
与time模块类似,datetime模块包含处理日期和时间所必需的所有方法。
内置功能:
下表介绍了本模块中的一些重要功能:
| function | Description |
|---|---|
| datetime() | datetime 的构造函数 |
| datetime.today() | 返回当前本地日期和时间 |
| datetime.now() | 返回当前本地日期和时间 |
| date() | 以年、月、日为参数,创建相应的日期 |
| time() | 以小时、分钟、秒、微秒和tzinfo作为参数,并创建相应的日期 |
| date.fromtimestamp() | 转换秒数以返回相应的日期和时间 |
| timedelta() | 它是不同日期或时间之间的差异(持续时间) |
使用 datetime 查找日期和时间


网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

被折叠的 条评论
为什么被折叠?



