File with date + time

Reply

Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

File with date + time

 
0
  #1
Oct 25th, 2005
I want to creat file with each line having date + time + data so I can append more data as need be and know when it was added. What date+time function would be best?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: File with date + time

 
0
  #2
Oct 25th, 2005
I just was messing around with the time module tonight. are you asking for something simple like
  1. >>> import time
  2. >>> time.ctime()
  3. 'Mon Oct 24 23:30:47 2005'
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: File with date + time

 
0
  #3
Oct 25th, 2005
That would do it - but maybe a little shorter is even better.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: File with date + time

 
0
  #4
Oct 25th, 2005
how about this
  1. import time
  2. # time.localtime() splits the time into elements of a tuple
  3. tuple_time = time.localtime()
  4. # don't europeans do day/month/year ?
  5. time_stamp = "%s:%s %s/%s/%s" %(tuple_time[3], tuple_time[4], tuple_time[2], tuple_time[1], tuple_time[0])
  6. print time_stamp

edit added later//

I noticed a time like one minute after 12 looks like this
  1. 0:1 25/10/2005

that could be fixed with a little more code
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: File with date + time

 
0
  #5
Oct 25th, 2005
this code fixes that issue
  1. def time_stamp():
  2. import time
  3. tuple_time = time.localtime()
  4. hours = tuple_time[3]
  5. if int(hours) in range(10):
  6. hours = "0%s" %hours
  7. minutes = tuple_time[4]
  8. if int(minutes) in range(10):
  9. minutes = "0%s" %minutes
  10. day = tuple_time[2]
  11. month = tuple_time[1]
  12. year = tuple_time[0]
  13. # don't europeans do day/month/year ?
  14. time_ = "%s:%s %s/%s/%s" %(hours, minutes, day, month, year)
  15. return time_
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: File with date + time

 
0
  #6
Oct 26th, 2005
That looks good. Many countries in Europe have day/month/year format, but that doesn't make much sense for what I may want to do. I am thinking about a date and time stamp starting each data line where the line could be sorted. It could have to look something like year/month/day hour:minute:second to do this rightly.

The tuple_time almost has this sorting format.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC