I want to create a UNIX timestamp for the date 2014-10-31
for every minute of the day. I have got a timestamp for the date but not for every minute -
import datetime
date = '2014-10-31'
t_stamp = int(time.mktime(datetime.datetime.strptime(date, "%Y-%m-%d").timetuple()))
print t_stamp
I want to save all these entries in a file which I need to access later to get specific entries only.
If I need to access one of the timestamp records using a date and specific time, how can it be done? For example, I need to find the entries for 2014-31-10
for the time between 20:00
and 20:05
, how can it be done?
Any help would be appreciated!
Updated:
import datetime
import ipaddress
from random import randint
for x in ip_range.hosts():
for h in range(24): #24 hours
for i in range(60): # 60 minutes
f.write(str(t_stamp)+'\t'+str(x)+'\t0\t'+str(randint(0,100))+'%\n')
f.write(str(t_stamp)+'\t'+str(x)+'\t1\t'+str(randint(0,100))+'%\n')
t_stamp += 60 # one minute
Now I am looking to create a log file for every minute. How can that be done?
t_stamp = int(time.mktime(datetime.datetime.strptime(date, "%Y-%m-%d").timetuple()))
for h in range(24): 24 hours
for i in range(60): # 60 minutes
print t_stamp
t_stamp += 60 # one minute
Hope this helps.
Storing timestamps in a database is simply redundant unless the required values cannot be corelated ie billing transactions' time. Here, your required range values have a start and end time, and you know them. You also know the interval between each value is 1 minute.
import datetime
tvalue = datetime.datetime(2014,10,31,0,0).timestamp() #yy mm dd 0 0
startval = ((REQD_HOUR)*3600 + (REQD_MIN)*60) #required start time
endval = ((REQD_HOUR_E)*3600 + (REQD_MIN_E)*60) # range end time
while (endval > startval):
print(tvalue+startval)
startval+=60
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.