This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

char text[500];

strcpy(text, ctime((const long *)&pTBoxDataBuffer[i].dwTimeStamp) );

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].dwTimeStamp)

'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.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 Neil

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.

<Gulp> What have I gotten myself into now?

The Neil

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.

dNewTime := StrToDate('01/01/1970')+

nNumOfSeconds

Now dNewTime will contain the appropriate time.

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.

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.

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

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

Hopefully this is what you're after. What it does is tobreak the seconds down into days, hours, minutes, and seconds. It then uses the number of days to calculate the years involved, and finally the months. The complexity comes in in the form of leap years but this handles them (or seems to)

function SecToDateTime(iNew : LONGINT): STRING;

VAR

dtNew : TDateTime;

years : INTEGER;

months : INTEGER;

days : INTEGER;

hours : INTEGER;

mins : INTEGER;

secs : INTEGER;

Day_Count : INTEGER;

n : INTEGER;

begin

days := iNew DIV (24 * 60 * 60);

iNew := iNew - (days * 24 * 60 * 60);

hours := iNew DIV (60 * 60);

iNew := iNew - (hours * 60 * 60);

mins := iNew DIV 60;

secs := iNew MOD 60;

//Hours, mins, and secs are fine now - just need to work out the months and years

//BUT we have to allow for leap years...

n := 0;

Years := 0;

REPEAT

n := n + 1;

IF ((n + 1970) MOD 4) = 0

THEN

Day_Count := 366

ELSE

Day_Count := 365;

IF days > Day_Count

THEN

BEGIN

Years := Years + 1;

days := days - Day_Count;

END;

UNTIL (Days <= Day_Count);

IF ((Years - 2) MOD 4) = 0 //Is THIS year a leap year?

THEN

BEGIN

IF Days < (31 + 29) //If we HAVEN'T gone past February 29th then we're

THEN //a day short (the above REPEAT loop will have taken

Days := Days + 1; //one too many off) so add a day back on

END;

//Days is now between 1 and 365 (or 366 in the case of a leap year)

Months := 0;

Day_Count := 31;

FOR n := 1 TO 12 //Iterate through the months until we find the one we need

DO //taking days off as we progress through the year

BEGIN

IF (Days <= Day_Count)

THEN

BEGIN

IF Months = 0

THEN

Months := n;

END

ELSE

Days := Days - Day_Count;

CASE (n + 1) OF

9, 4, 6, 11 : Day_Count := Day_Count + 30;

1, 3, 5, 7, 8, 10, 12 : Day_Count := Day_Count + 31;

2 : IF ((Years + 1970) MOD 4) = 0 //Handle leap years

THEN

Day_Count := Day_Count + 29

ELSE

Day_Count := Day_Count + 28;

END;

END;

dtNew := EncodeDate(years + 1970, months, days + 1) + EncodeTime(hours, mins, secs, 0);

Result := DateTimeToStr(dtNew);

end;

The Neil

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialWho 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 =:(

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.

because you had so much work, I'd like to ask aptalaptal to share the points - is this ok ?

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.

my functions works for me

ok grade TheNeils answer - as he said his function dosnt depend on date/time format

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

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.

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

Delphi

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

The Neil