473,463 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

time convert

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)
d '2003/04/25' h '14:42' z=ToNTPTime(d,h) 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
Jul 18 '05 #1
1 4665
Hello, Benoit!
You wrote on Tue, 1 Jul 2003 01:08:41 +0200:

BB> Thanks
BB> def ToNTPTime(d,h):
BB> "Retuen a NTP time"
BB> year,month,day=d.split("/")
BB> print "year,month,day=>",year,month,day
BB> hour,minute=h.split(":")
BB> print "hour,minute=>",hour,minute

BB> timeTuple=(int(year),int(month),int(day),int(hour) ,int(minute),int(0),i
BB> nt(0) ,int(0),int(0))
BB> print "Tuple for mktime=>"timeTuple,type(timeTuple)
BB> return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)
??>>>> d
BB> '2003/04/25'
??>>>> h
BB> '14:42'
??>>>> z=ToNTPTime(d,h)
BB> year,month,day=> 2003 04 25
BB> hour,minute=> 14 42
BB> Tuple for mktime=> (2003, 4, 25, 14, 42, 0, 0, 0, 0) <type 'tuple'>
BB> Traceback (most recent call last):
BB> File "<pyshell#42>", line 1, in ?
BB> z=NetworkTimeProtocolConvert.ToNTPTime(d,h)
BB> File "C:\Python21\_projet\NetworkTimeProtocolConvert.py ", line 38, in
BB> ToNTPTime
BB> return "%d" % (int(time.mktime((timeTuple))) + 2208988800L)
BB> AttributeError: mktime
??>>>>
BB> PS : sorry for my english

========================================
This one work with no errors
========================================
import time

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)

print ToNTPTime('2003/04/25','14:42')
========================================

With best regards, Egor Bolonev. E-mail: eb******@rol.ru

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
2
by: Rajmohan | last post by:
Hi All, I can convert a current time in time_t form to user understandable form using the apis - time, gmtime and strftime. How can i convert in the reverse way? ie take a time and date string...
5
by: ECVerify.com | last post by:
I am trying to convert a computers local time to Pacific time, I can get it back to UTC pretty easy but I actually want to convert whatever the local time is on the computer I want to calculate...
18
by: moni | last post by:
I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
4
by: Steve | last post by:
Hi All I need to compare date times from 2 different states in Australia in a Program I have which determines which way to update SQl server 2005 tables based on the lastupdate (datetime field)...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
3
by: Liming | last post by:
Hello All, In our project management software, we just noticed an issue. If team members are across the world, then there is an issue with due dates being consistent. (even though we have not...
0
amitpatel66
by: amitpatel66 | last post by:
Hi All, Find below some useful information about Time Zone Conversion in oracle. Hope this would be helpful for many of them since all the real time projects that we work in follow different time...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.