B
Benoit BESSE
Hi, I try to write a fonction which take a date and time and convert it into
a NTP time.
I have to use mktime but I did not work at all.
Here is my code dans the exécution.
Please help.
Thanks
def ToNTPTime(d,h):
"Retuen a NTP time"
year,month,day=d.split("/")
print "year,month,day=>",year,month,day
hour,minute=h.split(":")
print "hour,minute=>",hour,minute
timeTuple=(int(year),int(month),int(day),int(hour),int(minute),int(0),int(0)
,int(0),int(0))
print "Tuple for mktime=>"timeTuple,type(timeTuple)
return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)year,month,day=> 2003 04 25
hour,minute=> 14 42
Tuple for mktime=> (2003, 4, 25, 14, 42, 0, 0, 0, 0) <type 'tuple'>
Traceback (most recent call last):
File "<pyshell#42>", line 1, in ?
z=NetworkTimeProtocolConvert.ToNTPTime(d,h)
File "C:\Python21\_projet\NetworkTimeProtocolConvert.py", line 38, in
ToNTPTime
return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)
AttributeError: mktime
PS : sorry for my english
a NTP time.
I have to use mktime but I did not work at all.
Here is my code dans the exécution.
Please help.
Thanks
def ToNTPTime(d,h):
"Retuen a NTP time"
year,month,day=d.split("/")
print "year,month,day=>",year,month,day
hour,minute=h.split(":")
print "hour,minute=>",hour,minute
timeTuple=(int(year),int(month),int(day),int(hour),int(minute),int(0),int(0)
,int(0),int(0))
print "Tuple for mktime=>"timeTuple,type(timeTuple)
return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)year,month,day=> 2003 04 25
hour,minute=> 14 42
Tuple for mktime=> (2003, 4, 25, 14, 42, 0, 0, 0, 0) <type 'tuple'>
Traceback (most recent call last):
File "<pyshell#42>", line 1, in ?
z=NetworkTimeProtocolConvert.ToNTPTime(d,h)
File "C:\Python21\_projet\NetworkTimeProtocolConvert.py", line 38, in
ToNTPTime
return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)
AttributeError: mktime
PS : sorry for my english