Hi INTEL MASM Assembler coders:
Are we all comfy?
We ask for the time in Greenwich whick I think is near London and
on the Thames river. London, England i e United Kingdom.
We add one to the hour and save it in the wHour in
SYSTEMTIME strucure.
Here is the code!
; GERMTAG.ASM Sunday, March 08, 2009 12:22 PM
; Modified by herge Friday, September 20, 2013 8:04:09 AM EDT
; Eastern Daylight Time i e Toronto, Ontario, CANADA/Buffalo, New York, USA
.XCREF
.XLIST ; include \masm32\include\masm32rt.inc
include \masm32\include\masm32rt.inc
.LIST
.CREF
.data
dtbuf db 260 dup(0)
dd 0
TimBuf db 40 dup(0)
dd 0
DatLen dd 0
TimLen dd 0
AppName db "Date and time in Berlin:", 0
crlf db 13, 10, 0
tf db "hh:mm:ss tt", 0
;
; SYSTEMTIME has Eight 16 bit words there are:
;
; 1. CET.wYear ; Is the year.
; 2. CET.wMonth ; Is the month; January = 1, February = 2, and so on. 1 to 12.
; 3. CET.wDayOfWeek ; Is the day of the week; Sunday = 0, Monday = 1, and so on.
; ; 0 to 6, Sunday 0, 5 Friday, 6 Saturday.
; 4. GET.wDay ; Is the day of the month. 1 to 28 or 1 to 30 or 1 to 31.
; 5. CET.wHour ; Is the hour. 0 to 23
; 6. CET;wMinute ; Is the minute. 0 to 59
; 7. CET.wSecond ; Is the second. 0 to 59
; 8. CET.wMilliseconds ; Is the millisecond. 0 to 999
;
; LCID 2057 United Kingdom we do this so we get AM/PM.
;
; If your SYSTEMTIME is not CET. TRY yourName.wYear i e stm.wYear
; stm SYSTEMTIME<>; System Time
;
;wYear dw 0 ; 19?? or 2010 ... 1
;wMonth dw 0 ; 1 to 12, January, February, ... December. 2
;wToDay dw 0 ; Sunday 0, Monday 1, ... Saturday 6 3
;wDay dw 0 ; 1 to 28, 1 to 30, or 1 to 31. 4
; / ; February 1 to 29 leap Year.
;wHour dw 0 ; 1 to 23, 1 to 12. 5
;wMinute dw 0 ; 0 to 59 6
;wSecond dw 0 ; 0 to 59 7
;wMilliseconds dw 0 ; 0 to 999 8
;
; Days In Month
;
; JAN DD 31; 31 days in January 1
; FEB DD 28; is 29 in Leap Year 2
; MAR DD 31 3
; APR DD 30 4
; MAY DD 31 5
; JUN DD 30 6
; JUL DD 31 7
; AUG DD 31 8
; SEP DD 30 9
; OCT DD 31 10
; NOV DD 30 11
; DE12 DD 31 12
;
CET SYSTEMTIME<>; Central European Time
DaysInMonth equ $
JAN DD 31; 31 days in January
FEB DD 28; is 29 in Leap Year
MAR DD 31
APR DD 30
MAY DD 31
JUN DD 30
JUL DD 31
AUG DD 31
SEP DD 30
OCT DD 31
NOV DD 30
DE12 DD 31; Does not like DEC I think it's a reserved word?
DD 0; End of Table Marker
.code
align 8
start:
invoke GetSystemTime, addr CET; get UTC or GMT or England Time
mov ax, word ptr CET.wHour; Get Hour from SYSTEMTIME
inc ax; Make GMT + 1 i e German Time
mov word ptr CET.wHour, ax; Save Hour in SYSTEMTIME
;
invoke GetDateFormat, 1031, DATE_LONGDATE, 0, 0, addr dtbuf, 260
invoke lstrcat, addr dtbuf, addr crlf
push esi
mov esi, offset dtbuf
add esi, len(esi)
push esi
mov DatLen, eax
invoke GetTimeFormat, 2057, 0, addr CET, addr tf, addr TimBuf, 40
push offset TimBuf
call szLen
mov TimLen,eax
mov ecx, DatLen
sub ecx, eax
shr ecx, 1 ; Divide by two
pop esi
@@:
mov byte ptr [ esi ], 32
inc esi
dec ecx
jnz @B
invoke lstrcat, addr dtbuf, addr TimBuf
pop esi
invoke MessageBox, NULL, addr dtbuf, addr AppName, MB_OK
exit
ret
align 8
emd_here:
end start
Happy 50th Doctor Who Fans, it's in November, day after JFK got shot
in Dallas, Texas, USA.
Enjoy!
It's nice that you're playing, but world time is more complex than this.
Specifically, the correct time in Berlin is not simply UTC+1 -- you're ignoring daylight saving adjustments. So just adding 1 isn't enough.
Luckily, the OS has all of the information necessary to calculate the correct time in any given time zone, and will even do the calculation for you.
I suggest you do some research, and also look at the functionality actually provided by the datetime lib.
P.S. UTC and GMT are not the same thing.
Hi Tedd,
Quote from: Tedd on September 21, 2013, 12:13:49 AM
P.S. UTC and GMT are not the same thing.
from here (https://en.wikipedia.org/wiki/Coordinated_Universal_Time):
Quote
Coordinated Universal Time (UTC) is the primary time standard by which the world regulates clocks and time. It is one of several closely related successors to Greenwich Mean Time (GMT). For most purposes, UTC is synonymous with GMT, but GMT is no longer precisely defined by the scientific community.
In general, you're right: time question are a complex matter.
Gunther
i think we actually use "UTC Corrected Time"
but, as Gunther said, it is a complex issue
does anybody really know what time it is ? :biggrin:
25 or 6 to 4
Hi Dave,
Quote from: dedndave on September 21, 2013, 01:36:24 AM
does anybody really know what time it is ? :biggrin:
25 or 6 to 4
good question. I think it's
Chicago time (from the first album). :lol:
Gunther
Hi Tedd:
Yes GMt and UTC are not the same thing. But the documentation from the big M the
boys and girls ar Microsoft are NOT known for reliable information on ANY microsoft
software. The QA dept is slightly imcompetent, and not likely to improve any time soon
it generates money by support calls which ae billable?
NIST and NRC are nice places to get reliable time info. And I am sure there are similiar
government sites in Western Europe and else where in the world.
I have used Alex Lyons Library and am having problems with it.
I think I am missing something, the year is wrong and the time is off, but I think the code
is good and I think I miss understanding some concept.
Hi Guys & Gals:
To fix the zero hour problem do this:
invoke GetLocalTime, addr stm ; aka UTC Time
mov ax, stm, wHour
and ax, ax
jnz @F
add ax, 12 ; It's just past Mid Night i e hour zero!
mov stm.wHour, ax
@@:
I think you should do it your self.
i e time just after mid night i e 12 PM +.
invoke GetLocalTime, addr stm ; aka UTC Time
if you want UTC time, use GetSystemTime, no ?
Hi DednDav:
I cheated I adjusted my Time Zone and did some research. On Windows XP touch the
time bottom right corner. Check out CUT and GMT time. CUT C.. Universal Time and
GMT Greenwich Mean Time i e London England i e United Kingdom.
Adjust Date/Time and click on Time Zone. Adjust back after you run Program?
Cut and GMT are off by one at the moment, but do not count on it?
Remember to Adjust back.
C:\masm32\bin>showtime
Monday, September, 23, 2013 06:29 AM Eastern Daylight Time EDT
Monday, September, 23, 2013 06:30 AM EDT
<< Hit Space Bar to END Process >>
C:\masm32\bin>showtime
Monday, September, 23, 2013 11:09 AM Coordinated Universal Time CUT
Monday, September, 23, 2013 11:09 AM CUT
<< Hit Space Bar to END Process >>
C:\masm32\bin>showtime
Monday, September, 23, 2013 12:09 PM GMT Daylight Time GDT
Monday, September, 23, 2013 12:09 PM GDT
<< Hit Space Bar to END Process >>
C:\masm32\bin>showtime
Monday, September, 23, 2013 07:10 AM Eastern Daylight Time EDT
Monday, September, 23, 2013 07:10 AM EDT
<< Hit Space Bar to END Process >>
Remember to adjust back after test!
i don't have the ShowTime source or program :biggrin:
i don't understand why you have so much trouble
i use XP sp3, and everything seems to work well
i use the nist time server, so it doesn't do to set the time - it corrects itself :P
Hi dednDav:
By Popular Demand, i e One Request?
I used showtime because it is a console output so is easy to Copy?
This is SHOWTIME.ASM
; REM SHOWTIME.ASM Thursday, September 12, 2013 2:16:56 PM
; Modified Thursday, September 19, 2013 8:38:47 AM
; Just for DednDav by Popular Demand
; Requested on Monday, September, 23, 2013 07:40 AM EDT
; by herge - Show System Date & Time
; Console Build Please!
include \masm32\include\masm32rt.inc
INCLUDE \masm32\include\DateTime.inc
INCLUDELIB \masm32\lib\DateTime.lib
.data
stm SYSTEMTIME<>
org stm; Must be eight words
wYear dw 0
wMonth dw 0
wToDay dw 0 ; Sunday 0 to Saturday 6
wDay dw 0
wHour dw 0
wMinute dw 0
wSecond dw 0
wKsecond dw 0
TZptr dd 0
ZeroSpace db " "; Space
short_buf db 128 dup (0)
db 0
FirstSpace db " "
date_buf db 128 dup (0)
SecondSpace db " "
Time_Zone_buf db 128 dup(0)
time_buf db 32 dup (0)
db 0
dateformat db "dddd, MMMM, dd, yyyy", 0
timeformat db "hh:mm tt",0
CrLf db 13, 10, 0
db 0
align 8
.code
start:
invoke GetDateFormat, 0, 0, \
0, ADDR dateformat, ADDR date_buf, sizeof date_buf
mov ecx, offset date_buf
add ecx, eax; add length returned by GetDateFormat
mov byte ptr [ecx-1], " " ;replace null with space
invoke GetTimeFormat, 0, 0, \
0, ADDR timeformat, ecx, sizeof time_buf
PTZ:
cld ; Direction Flag Up
mov esi, offset date_buf
mov edi, offset short_buf
@@:
lodsb
and al, al
jnz @B
dec esi
mov byte ptr [esi]," " ; remove zero
inc esi
mov [TZptr], esi
INVOKE CurrentTimeZoneName, esi
inc eax
jz err_tz
public TimeZone
TimeZone:
mov esi, [TZptr]
mov edi, offset short_buf
lodsb
stosb ; First letter
@@:
lodsb
cmp al," "
jnz @B
lodsb
stosb
@@:
lodsb
and al, al
jz @F
cmp al, " "
jnz @B
lodsb
stosb
@@:
lodsb
and al, al
jnz @B
mov byte ptr [ esi ], al
mov byte ptr [ edi ], al
invoke CurrentTimeZoneName, ADDR Time_Zone_buf
invoke StdOut, ADDR FirstSpace
invoke StdOut, ADDR ZeroSpace
invoke MessageBox, 0, addr date_buf, addr date_buf, MB_OK
invoke GetDateFormat, 0, 0, \
0, ADDR dateformat, ADDR date_buf, sizeof date_buf
mov ecx, offset date_buf
add ecx, eax; add length returned by GetDateFormat
mov byte ptr [ecx-1], " " ;replace null with space
invoke GetTimeFormat, 0, 0, \
0, ADDR timeformat, ecx, sizeof time_buf
mov al, 0
mov edi, [TZptr]
stosb
invoke lstrcat, addr date_buf, addr ZeroSpace ; Date+Short Time Zone
invoke StdOut, ADDR CrLf
invoke StdOut, ADDR FirstSpace
invoke StdOut, ADDR CrLf
inkey " << Hit Space Bar to END Process >> "
invoke ExitProcess, 0
ret
err_tz:
print " << Time Zone Not Set >> ",7,13,10; 7 = Bell Noise i e Alarm
exit
ret
align 8
end_here equ $
end start
That's All Folks!
I watched too many Warner Bros. Cartoons in my youth.
Hi DednDav:
org stm; Must be eight words
wYear dw 0
wMonth dw 0
wToDay dw 0 ; Sunday 0 to Saturday 6
wDay dw 0
wHour dw 0
wMinute dw 0
wSecond dw 0
wKsecond dw 0
You Do Not need this, but it is Good documention I sometimes
forget the components of <SYSTEMTIME> eight sixteen bit words.
You just need the
stm SYSTEMTIME<>
invTime:
invoke GetLocalTime, addr stm ; aka Local Time
mov ax, stm,wHour
and ax, ax
jnz @F
add ax, 12 ; It's just past Mid Night i e hour zero!
mov stm.wHour, ax; save hour in stm
@@:
ohhhhh
you are using the DateTime code by Lyons :P
not sure how he gets the local time zone name string, but you can't get it from the time numbers :redface:
you should not have to correct for midnight
the trick is - don't use the DateTime inc/lib - lol
Hi Dedndave:
You will need the DateTime.INC
and the DAteTime.lib and ...
Esi will point to a Ascii Zero buffer.
mov esi,offset PtrTimeZoneBuf
INVOKE CurrentTimeZoneName, esi
if i wanted the time zone name, i would use GetTimeZoneInformation :t