![]()
import time
#打印当前时间,是从1970年1月1日到现在的秒数
t1 = time.time()
#打印结构化时间
t2 = time.localtime(1534042206.0)
#将结构化时间转换为时间戳
t3 = time.mktime(time.localtime(1634042206.0))
#print(t1, t2, t3)
#将结构化时间转换为字符串形式,我们通常见到的形式
t4 = time.strftime("%Y-%m-%d %X", time.localtime())
#print(t4)
#将字符串转化为结构化时间 ,%X 将相当于时分秒的形式了
t5 = time.strptime("2018-08-12 10:58:40", "%Y-%m-%d %X")
#print(t5)
t6 = time.asctime()
print(t6)
t7 = time.ctime()
#print(t7)
import datetime
'''更好看的一种形式'''
t8 = datetime.datetime.now()
print(t8)
随机数模块
import random
#0到1之间的浮点数
r1 = random.random()
#print(r1)
#取给定的值
r2 = random.randint(1,3)
#print(r2)
#取给定的值,左取右不取
r3 = random.randrange(1,3)
#print(r3)
#取给定的值
r4 = random.choice([i for i in range(10)])
#print(r4)
r5 = random.sample([11,22,33,44,66],2)
#print(r5)
#取给定值的任意数(包括小数和整数)
r6 = random.uniform(1,4)
#print(r6)
#打乱一个给定的列表
# ret = [i for i in range(10)]
# random.shuffle(ret)
# print(ret)
str1 = ""
for i in range(5):
num1 = random.randint(0, 9)
cha1 = chr(random.randint(65,122))
s = str(random.choice([num1, cha1]))
str1 += s
print(str1)