I am playing around with GetSystemTime and GetTimeFormat so I can name some files and have noticed that GetSystemTime returns the wrong time!

I use 24 hour format and now it is 1547 and GetSystemTime returns 2047! why?



TestMe proc
LOCAL syst:SYSTEMTIME
LOCAL CurTime[6]:BYTE
LOCAL BufSize:DWORD

lea eax, syst
push eax
call GetSystemTime

mov BufSize, 6
lea eax, BufSize
push eax
lea ecx, CurTime
push ecx
push offset szTimeFormat
lea edx, syst
push edx
push TIME_FORCE24HOURFORMAT
push NULL
call GetTimeFormat

lea eax, CurTime
PrintStringByAddr eax
ret

TestMe endp
Posted on 2003-03-06 14:52:30 by Gunner
I think you need to use GetLocalTime to account for any differences with your BIOS
Posted on 2003-03-06 15:00:16 by Hiroshimator
oooooooh, replaced GetSystemTime with GetLocalTime and works like a charm now!

Thanks Hiro.
Posted on 2003-03-06 15:08:17 by Gunner
@Gunner

Your code doesnt wor at me.

Its cause a crash
:confused: :confused: :confused: :confused:

szTimeFormat is DB type, right ?

and PrintStringByAddr is a macro, right ?

good night at all !
Posted on 2003-03-08 16:27:52 by Forginforcer
szTimeFormat is declared as a BYTE in the .data section wiht a string on how I want the time formated, look up GetTimeFormat for the format. In my case I have:

szTimeFormat BYTE 'HHmmss', 0

PrintStringByAddr is part of the debug macros I use in RadASM
Posted on 2003-03-08 17:33:02 by Gunner
hmm, I get strenge Results. - Something like 99093.
I replaced the nasm-macro with this "INVOKE lstrcpy, ADDR buff11, eax", and via MessageBox I checked the effect.

I thought, with this code its possible to get the system date :confused:

P.S. I used GetSystemTime and GetLocal?Time, both cause comical results.
Posted on 2003-03-09 02:12:24 by Forginforcer
Yes, GetLocalTime does return the date. It returns the year, day, month, hour, minute, second and millisecond.
No it does not return 3/9/03 0930 or March 9, 2003 930PM. It is up to you to format the date how you want.

Look up SYSTEMTIME for mor info. Here is a sample to get the year/month/day in MASM:
dwtoa converts a DWORD to an ascii string.



CreateFileName proc FileName:DWORD
LOCAL syst:SYSTEMTIME
LOCAL sYear[5]:BYTE
LOCAL sMonth[3]:BYTE
LOCAL sDay[3]:BYTE

lea eax, syst
push eax
call GetLocalTime

lea eax, sYear
push eax
xor ecx, ecx
mov cx, syst.wYear
push ecx
call dwtoa

lea eax, sMonth
push eax
xor ecx, ecx
mov cx, syst.wMonth
push ecx
call dwtoa

lea eax, sDay
push eax
xor ecx, ecx
mov cx, syst.wDay
push ecx
call dwtoa

invoke szMultiCat, 3, FileName, addr sYear, addr sMonth, addr sDay

ret
CreateFileName endp

and to call it:


LOCAL TempFileName[11]:BYTE

push 0
push 11
lea eax, TempFileName
push eax
call memfill

lea eax, TempFileName
push eax
call CreateFileName

push 0
push 0
lea eax, TempFileName
push eax
push 0
call MessageBox


the message box will display 200339 today.
Posted on 2003-03-09 08:46:29 by Gunner