473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ 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.s plit(":")
print "hour,minute=>" ,hour,minute

timeTuple=(int( year),int(month ),int(day),int( hour),int(minut e),int(0),int(0 )
,int(0),int(0))
print "Tuple for mktime=>"timeTu ple,type(timeTu ple)
return "%d" % (int(time.mktim e((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#4 2>", line 1, in ?
z=NetworkTimePr otocolConvert.T oNTPTime(d,h)
File "C:\Python21\_p rojet\NetworkTi meProtocolConve rt.py", line 38, in
ToNTPTime
return "%d" % (int(time.mktim e((timeTuple))) + 2208988800L)
AttributeError: mktime


PS : sorry for my english
Jul 18 '05 #1
1 4681
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.s plit(":")
BB> print "hour,minute=>" ,hour,minute

BB> timeTuple=(int( year),int(month ),int(day),int( hour),int(minut e),int(0),i
BB> nt(0) ,int(0),int(0))
BB> print "Tuple for mktime=>"timeTu ple,type(timeTu ple)
BB> return "%d" % (int(time.mktim e((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#4 2>", line 1, in ?
BB> z=NetworkTimePr otocolConvert.T oNTPTime(d,h)
BB> File "C:\Python21\_p rojet\NetworkTi meProtocolConve rt.py", line 38, in
BB> ToNTPTime
BB> return "%d" % (int(time.mktim e((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.s plit(":")
print "hour,minute=>" ,hour,minute

timeTuple=(int( year),int(month ),int(day),int( hour),int(minut e),int(0),int(0 )
,int(0),int(0))
print "Tuple for mktime=>",timeT uple,type(timeT uple)
return "%d" % (int(time.mktim e((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
5206
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 Duration (int) - the duration in minutes of the work block. In another table called OvertimeRates I have information about rate multipliers and a column that tells me the TIME that the rate
2
13368
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 in the form "Thu, 21 Feb 2002 13:02:03 GMT" and convert into time_t seconds? Is there any c library api available for accomplishing this? Thanks in advance,
5
5798
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 what it would currently be in Pacific time. Taking in account Daylight Savings Time Thanks, Ed,
18
3121
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
14600
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 = '2007-03-13T15:00:00Z' I want to convert it to my local time. start_time = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M:
8
6057
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 app. 3. I need to convert the received date string in to a date w.r.t my local time zone.
4
3906
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) datetime Each location updates the lastupdate field based on the current local datetime at the the time of saving to SQL server Perth for example is 2 hours behind Melbourne
18
13046
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 1901. For Example: the number 3566839 is 27.11.07 7:00. To calculate this in Excel I use this: ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put 3566839 in field A1 and switch the format of the result-field to the corresponding...
3
2368
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 yet had such customers, but we want to address this) For example. A team is consists of 3 team members. John (U.S Eastern time), Jack
0
19600
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 zones (EST,PST etc) and you might well need to convert them to something specific as per your requirements: insert into dates values(6, to_date('09/20/05 23:15', 'MM/DD/YY HH24:MI')); --The contents of the table now look like this: 1...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8958
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.