用time来获取和格式化当前时间。
import time
now = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
# or
# now = time.strftime("%Y%m%d%H%M%S", time.localtime())
print(now)
常用格式化符号:
%Y 四位数的年,如2019
%m 月,01-12
%d 天,00-31
%H 小时,00-23
%M 分钟,00-59
%S 秒,00-59
由于秒是一直在变的,所以在Perl或者Shell里一般用秒来作为仿真种子。但python里的秒是符点数,而仿真器需要一个整数。所以我们需要自己做一个整数型种子。
import
seed = time.strftime("1%d%H%M%S", time.localtime(time.time()))
print("-svseed " + seed)
例如,由于“20191022094010”超出了32bit整数的范围,我们把年份和月份去掉。另外天数可能是零开头,所以天数前面加一个1,变成“122094010”。