- 论坛徽章:
- 6
|
本帖最后由 stanley_tam 于 2016-07-04 20:30 编辑
这样? - #!python
- #-*-coding:utf-8 -*-
- import time
- import datetime
- import random
- def gen_randome_time(start_time, end_time):
- start_time_stamp = int(time.mktime(time.strptime(start_time, "%Y-%m-%d")))
- end_time_stamp = int(time.mktime(time.strptime(end_time, "%Y-%m-%d")))
- rand_time_stamp = list(range(start_time_stamp,end_time_stamp,random.randrange(100000,999999,100)))
- timestamp = random.sample(rand_time_stamp,1)
- datearray = datetime.datetime.utcfromtimestamp(float(timestamp[0]))
- styletime = datearray.strftime("%m" + "/" + "%d" + "/" + "%Y")
- return styletime
- def main():
- start_time = "2010-01-01"
- end_time = "2015-12-31"
- styletime = gen_randome_time(start_time, end_time)
- print("The Random time:" + styletime)
- if __name__ == '__main__':
- main()
复制代码 回复 3# kingmary
|
|