aptalaptal
asked on
Equivalent Delphi or Win32 API function of 'ctime' of MS VC++
char text[500];
strcpy(text, ctime((const long *)&pTBoxDataBuffer[i].dwTi meStamp) );
text[strlen(text)-1]=0; // remove final \n
printf(" %s \n", text);
i have to do the same what the code above does.
Does anybody know the Delphi equivalent of 'ctime' function of MS VC++?
ctime((const long *)&pTBoxDataBuffer[i].dwTi meStamp)
'dwTimestamp' holds ' seconds since 01/01/70 00:00:00 GMT+0 ', called UTC.
Does anybody know Delphi equivalent or Win32 API of this 'ctime ' function?
It is urgent.
Thanks in advance for your help.
strcpy(text, ctime((const long *)&pTBoxDataBuffer[i].dwTi
text[strlen(text)-1]=0; // remove final \n
printf(" %s \n", text);
i have to do the same what the code above does.
Does anybody know the Delphi equivalent of 'ctime' function of MS VC++?
ctime((const long *)&pTBoxDataBuffer[i].dwTi
'dwTimestamp' holds ' seconds since 01/01/70 00:00:00 GMT+0 ', called UTC.
Does anybody know Delphi equivalent or Win32 API of this 'ctime ' function?
It is urgent.
Thanks in advance for your help.
What does the CTime routine do in MS VC++?
The Neil
The Neil
Yo could see the win32.hlp's entry for getSystemTime:
The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime // address of system time structure
);
GL
Mike
The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime // address of system time structure
);
GL
Mike
I'm lost as to what you're ultimately trying to do. As I see it you're getting this value which holds the number of seconds from 1st Jan 1970, and then converts it to a string. Are you trying to store and output dates since 1st Jan 1970? As far as I know there's no in built Delphi routine to do this (the seconds and 1970 bit anyway) but writing a routine to convert your integer value and add in the offset is pretty easy to do (ask if you want it writing)
The Neil
The Neil
ASKER
TheNeil
would you write such a function for me to convert an integer number (holding seconds since 01/01/70 00:00:00 GMT + 0)?
then i will give you all the points.
would you write such a function for me to convert an integer number (holding seconds since 01/01/70 00:00:00 GMT + 0)?
then i will give you all the points.
I'll give it a try. Just to avoid confusion, you want a routine that is supplied with the number of seconds since 01/01/70 00:00:00 and returns a string containing the actual date (e.g. given 86461 (1 day 1 minute, and 1 second) it would return 02/01/70 00:01:01 as a string)
<Gulp> What have I gotten myself into now?
The Neil
<Gulp> What have I gotten myself into now?
The Neil
ASKER
edey,
i m not dealing with system time. i have the number of seconds from 01/01/70 00:00:00 GMT+0.
MS VC++ 5.0 and ,i guess, older versions of VC++ have 'ctime ' function to convert seconds into a stirng format like :
Thu Jan 20 19:36:11 2000 .
but thank you for your interest. :)
waiting for your any other help.
i m not dealing with system time. i have the number of seconds from 01/01/70 00:00:00 GMT+0.
MS VC++ 5.0 and ,i guess, older versions of VC++ have 'ctime ' function to convert seconds into a stirng format like :
Thu Jan 20 19:36:11 2000 .
but thank you for your interest. :)
waiting for your any other help.
If you have the number of seconds since 1/1/70 00:00:00 GMT+0, why not just add this value to a date value, i.e.
dNewTime := StrToDate('01/01/1970')+
nNumOfSeconds
Now dNewTime will contain the appropriate time.
dNewTime := StrToDate('01/01/1970')+
nNumOfSeconds
Now dNewTime will contain the appropriate time.
ASKER
TheNeil
you are thoroughly right :)
i have an integer value represents seconds from 01/01/1970 00:00:00 .
i need a function to convert that integer value (i mean seconds) into a string like
seconds string
948396971 ---> 20/01/2000 19:36:11
function SecToDateTime(second:integ er):string ;
begin
???
end;
does anybody do that or know a win32 API or object pascal function???
this is very important to me.
you are thoroughly right :)
i have an integer value represents seconds from 01/01/1970 00:00:00 .
i need a function to convert that integer value (i mean seconds) into a string like
seconds string
948396971 ---> 20/01/2000 19:36:11
function SecToDateTime(second:integ
begin
???
end;
does anybody do that or know a win32 API or object pascal function???
this is very important to me.
ASKER
JoeBooth,
can you convert the number '948396971' (that is the seconds from 01/01/1970 00:00:00 ) into
this string : 20/01/2000 19:36:11 ?
seconds ---> string
948396971 ---> '20/01/2000 19:36:11 '
this is what 'ctime' function in C++ does.
this is also what i want to do in Delphi.
thanks and waiting for your any suggestions.
can you convert the number '948396971' (that is the seconds from 01/01/1970 00:00:00 ) into
this string : 20/01/2000 19:36:11 ?
seconds ---> string
948396971 ---> '20/01/2000 19:36:11 '
this is what 'ctime' function in C++ does.
this is also what i want to do in Delphi.
thanks and waiting for your any suggestions.
ASKER
JoeBooth,
can you convert the number '948396971' (that is the seconds from 01/01/1970 00:00:00 ) into
this string : 20/01/2000 19:36:11 ?
seconds ---> string
948396971 ---> '20/01/2000 19:36:11 '
this is what 'ctime' function in C++ does.
this is also what i want to do in Delphi.
thanks and waiting for your any suggestions.
can you convert the number '948396971' (that is the seconds from 01/01/1970 00:00:00 ) into
this string : 20/01/2000 19:36:11 ?
seconds ---> string
948396971 ---> '20/01/2000 19:36:11 '
this is what 'ctime' function in C++ does.
this is also what i want to do in Delphi.
thanks and waiting for your any suggestions.
Joe,
948396971 is the number of seconds from 1st Jan 1970, the problem is, adding on the time UP TO the 1st Jan 1970
The Neil
948396971 is the number of seconds from 1st Jan 1970, the problem is, adding on the time UP TO the 1st Jan 1970
The Neil
Joe,
948396971 is the number of seconds from 1st Jan 1970, the problem is, adding on the time UP TO the 1st Jan 1970
The Neil
948396971 is the number of seconds from 1st Jan 1970, the problem is, adding on the time UP TO the 1st Jan 1970
The Neil
try this one:
function SecToDate(x:integer):strin g;
var x1Day,x1Hour,x1Min,x1Sec,d ate:TDateT ime;
yDay,yHour,yMin,ySec:integ er;
s:string;
begin
x1Day:=StrToDateTime('02.0 1.1980')-S trToDateTi me('01.01. 1980');
x1Hour:=StrToDateTime('01. 01.1980 02:00:00')-StrToDateTime(' 01.01.1980 01:00:00');
x1Min:=StrToDateTime('01.0 1.1980 01:01:00')-StrToDateTime(' 01.01.1980 01:00:00');
x1Sec:=StrToDateTime('01.0 1.1980 01:00:01')-StrToDateTime(' 01.01.1980 01:00:00');
yDay:=x div 86400;
yHour:=(x - (yDay*86400)) div 3600;
yMin:=((x - (yDay*86400)) - (yHour*3600)) div 60;
ySec:=((x - (yDay*86400)) - (yHour*3600)) - (yMin*60);
date:=StrToDateTime('01.01 .1970 00:00:00')+
yDay*x1Day+yHour*x1Hour+yM in*x1Min+y Sec*x1Sec;
Result:=FormatDateTime('dd .mm.yyyy hh:nn:ss',date);
end;
you have to ajust the dates and times to your time format
good luck
function SecToDate(x:integer):strin
var x1Day,x1Hour,x1Min,x1Sec,d
yDay,yHour,yMin,ySec:integ
s:string;
begin
x1Day:=StrToDateTime('02.0
x1Hour:=StrToDateTime('01.
x1Min:=StrToDateTime('01.0
x1Sec:=StrToDateTime('01.0
yDay:=x div 86400;
yHour:=(x - (yDay*86400)) div 3600;
yMin:=((x - (yDay*86400)) - (yHour*3600)) div 60;
ySec:=((x - (yDay*86400)) - (yHour*3600)) - (yMin*60);
date:=StrToDateTime('01.01
yDay*x1Day+yHour*x1Hour+yM
Result:=FormatDateTime('dd
end;
you have to ajust the dates and times to your time format
good luck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The Neil - you dont like my function ? why ?
Egono
Who said I don't like your function? Admittedly I've sworn at you and your family since I spotted appearing ONE MINUTE before mine but it's small, neat, and elegant so you do gain some admiration. It's a bit confusing though and yours might fall over if the date/time format is different while mine will work on any machine (regardless of the date/time format).
Here I was all pleased that I'd got the damn thing working and you pop up with an alternative - grrrrr (I really fancied those points as well)
The Neil =:(
Who said I don't like your function? Admittedly I've sworn at you and your family since I spotted appearing ONE MINUTE before mine but it's small, neat, and elegant so you do gain some admiration. It's a bit confusing though and yours might fall over if the date/time format is different while mine will work on any machine (regardless of the date/time format).
Here I was all pleased that I'd got the damn thing working and you pop up with an alternative - grrrrr (I really fancied those points as well)
The Neil =:(
ASKER
egono,
i tried your code but not working properly.
i gave 948396971, which is expected to display
20/01/2000 19:36:11, to your function .
but it returned 04/08/2901 19:36:11 which is wrong.
i tried your code but not working properly.
i gave 948396971, which is expected to display
20/01/2000 19:36:11, to your function .
but it returned 04/08/2901 19:36:11 which is wrong.
The Neil - I've wrote these function about a year ago and as I saw the question I remembered me - i just copied it from the old source
because you had so much work, I'd like to ask aptalaptal to share the points - is this ok ?
because you had so much work, I'd like to ask aptalaptal to share the points - is this ok ?
ASKER
egono,
i tried your code but not working properly.
i gave 948396971, which is expected to display
20/01/2000 19:36:11, to your function .
but it returned 04/08/2901 19:36:11 which is wrong.
i tried your code but not working properly.
i gave 948396971, which is expected to display
20/01/2000 19:36:11, to your function .
but it returned 04/08/2901 19:36:11 which is wrong.
aptalaptal - did you change the date and time format ?
my functions works for me
ok grade TheNeils answer - as he said his function dosnt depend on date/time format
my functions works for me
ok grade TheNeils answer - as he said his function dosnt depend on date/time format
Aptalaptal
If you try my code then you'll see that 948396971 does return the correct value. Egono's code works on my machine but I think this may come down to the problem that I highlighted to him - the date/time format is potentially different on different machines.
The Neil
If you try my code then you'll see that 948396971 does return the correct value. Egono's code works on my machine but I think this may come down to the problem that I highlighted to him - the date/time format is potentially different on different machines.
The Neil
ASKER
i think it would be unfair to TheNeil to divide the points.
sorry egono:(
but thank you for your help.
theneil worked hard on this question.
i am giving you the points.
thanks theneil. it works properly.
take care of yourselves, all who commented on this question.
sorry egono:(
but thank you for your help.
theneil worked hard on this question.
i am giving you the points.
thanks theneil. it works properly.
take care of yourselves, all who commented on this question.
ASKER
bye until the next question.
take care:)
take care:)
Thanks Aptalaptal (and I did work hard on this one). Have you accepted my comment as an answer or do you want me to submit another message as an answer?
All I can say Egono is sorry, when it came down to it, my code worked and your's didn't - next time it might be the other way round (probably will be knowing my code)
The Neil
All I can say Egono is sorry, when it came down to it, my code worked and your's didn't - next time it might be the other way round (probably will be knowing my code)
The Neil
that's life - congratulation TheNeil, you worked hard for it :)
The Neil