News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Time Zone with datetime.lib

Started by herge, August 17, 2013, 04:02:56 PM

Previous topic - Next topic

herge

 Hi Time Zone Fans:

With help from Mr. Lyon I have put this program together we are using the datetime.lib

Enjoy Time Zone Fans:

; timezone.asm Tuesday, November 17, 2009 7:05:56 AM
; modified by herge Saturday, August 17, 2013 6:16:22 AM
; Console Build Please!
; Source Masm32\datetime\ctzn.asm
include \masm32\include\masm32rt.inc
INCLUDE \masm32\include\DateTime.inc
INCLUDELIB \masm32\lib\DateTime.lib
.DATA
LOCALE_SYSTEM_DEFAULT equ 0
stm  SYSTEMTIME<>
dateformat  db " dddd, MMMM, dd, yyyy", 0
timeformat db "hh:mm:ss tt",0
pzTitle     db "UTC or GMT or London England Time "
date_buf db 260 dup (?)
      db 20 dup (?)
            db    0
FirstSpace  db    " " ; Add a Space!
StdOutBuf   db    148 dup(0)
            db    0
.CODE
;---------------------------------------
start:
     cld    ; Direction Flag Up
     mov    esi, offset StdOutBuf
     INVOKE CurrentTimeZoneName, esi
     inc    eax
     jz     err_tz
@@:     
     lodsb
     and    al, al
     jnz    @B
     
     mov    word ptr [ esi-1 ], 0A0Dh ; Crlf
     inc    esi
     mov    byte ptr [ esi ], 0

invTime:    invoke GetSystemTime, addr stm ; aka UTC Time
; Print Date
invFor: invoke GetDateFormat, LOCALE_SYSTEM_DEFAULT, 0, \
ADDR stm, ADDR dateformat, ADDR date_buf, 240
mov ecx, offset date_buf
add ecx, eax; add length returned by GetDateFormat
mov byte ptr [ ecx-1 ], ' ';replace null with space
; Print Time!
invPrt: invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT, NULL, \
                  ADDR stm, ADDR timeformat, ecx, 20
     invoke lstrcat, addr date_buf, addr FirstSpace

invMess: invoke MessageBox, 0,  addr pzTitle, addr date_buf, MB_OK
     inkey
     exit
err_tz:
    print   "Time Zone Not Set",13,10
    inkey
    exit
    END start
; D:\masm32\Bin\timezone.asm


Enjoy Time Zone Fans!



Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge


I have just noticed after a number of compiles that the time zone at the end of
message box is the computer's Time Zone Not London's Time Zone which I
presume is British Summer Time. The time is UTC or GMT or BST or London
England i e LHR london Heathrow Airport time. But i digress!

But it does it's job any way!
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge


A simple example for Your Local Time with time zone name.

; timezone.asm Tuesday, November 17, 2009 7:05:56 AM
; modified by herge Saturday, August 17, 2013 6:44:09 AM
; Console Build Please!
; Source Masm32\datetime\ctzn.asm
INCLUDE \masm32\include\masm32rt.inc
INCLUDE \masm32\include\DateTime.inc
INCLUDELIB \masm32\lib\DateTime.lib
.DATA
LOCALE_SYSTEM_DEFAULT equ 0
stm  SYSTEMTIME<>
dateformat  db " dddd MMMM dd, yyyy", 0
timeformat db "hh:mm:ss tt",0
pzTitle     db "Your Local Time & time Zone "
date_buf db 260 dup (?)
      db 20 dup (?)
            db    0
FirstSpace  db    " " ; Add a Space!
StdOutBuf   db    148 dup(0)
            db    0
.CODE
;---------------------------------------
start:
     cld    ; Direction Flag Up
     mov    esi, offset StdOutBuf
     INVOKE CurrentTimeZoneName, esi
     inc    eax
     jz     err_tz
@@:     
     lodsb
     and    al, al
     jnz    @B
     
     mov    word ptr [ esi-1 ], 0A0Dh ; Crlf
     inc    esi
     mov    byte ptr [ esi ], 0

invTime:    invoke GetLocalTime, addr stm ; aka UTC Time
; Print Date
invFor: invoke GetDateFormat, LOCALE_SYSTEM_DEFAULT, 0, \
ADDR stm, ADDR dateformat, ADDR date_buf, 240
mov ecx, offset date_buf
add ecx, eax; add length returned by GetDateFormat
mov byte ptr [ ecx-1 ], ' ';replace null with space
; Print Time!
invPrt: invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT, NULL, \
                  ADDR stm, ADDR timeformat, ecx, 20
     invoke lstrcat, addr date_buf, addr FirstSpace

invMess: invoke MessageBox, 0,  addr pzTitle, addr date_buf, MB_OK
     exit
err_tz:
    print   "Time Zone Not Set",13,10
    exit
    END start
; D:\masm32\Bin\timezone.asm


Enjoy!
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

minor28

#3
If you are interested of timezone anywhere on earth I have a program for that. You can get the program and source code at http://minor28.divdev.se/index.php?sc

herge

#4
 Hi minor28;

That web site complained about cookies i e is DNW i e Does Not Work!
or FORD Found On Road Dead or Fix Or Repair Daily. A Dearborn Car
Maker next to Detriot Michigan USA. The city of Detriot has declared
Bankruptcy. i e went tits Up?
I think I talked about this in a previous post of mine.
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge


Hi *.*:

i e All, This is timzonw.asm a windows program.

; timzonw.asm Tuesday, November 17, 2009 7:05:56 AM
; modified by herge Sunday, August 18, 2013 6:38:31 AM
; Windows Build Please!
; So No inkey or StdOut or print please?
; Source Masm32\datetime\ctzn.asm
INCLUDE \masm32\include\masm32rt.inc
INCLUDE \masm32\include\DateTime.inc
INCLUDELIB \masm32\lib\DateTime.lib
.DATA
; LOCALE_SYSTEM_DEFAULT equ 0
stm  SYSTEMTIME<>
dateformat  db " dddd MMMM dd, yyyy", 0
timeformat db "hh:mm tt",0
pzTitle     db "Your Local Time & Time Zone "
date_buf db 260 dup (?)
      db 20 dup (?)
            db    0
FirstSpace  db    " " ; Add a Space!
StdOutBuf   db    148 dup(0)
            db    0
TimeZoneNotSet db "Time Zone Not Set", 13, 10, 7, 0; 7 should be a bell sound?
               
.CODE
;---------------------------------------
start:
     cld    ; Direction Flag Up
     mov    esi, offset StdOutBuf
     INVOKE CurrentTimeZoneName, esi
     inc    eax
     jz     err_tz
@@:     
     lodsb
     and    al, al
     jnz    @B
     
     mov    byte ptr [ esi ], 0

invTime:    invoke GetLocalTime, addr stm ; aka UTC Time
; Print Date
invFor: invoke GetDateFormat, 0, 0, \
ADDR stm, ADDR dateformat, ADDR date_buf, 240
mov ecx, offset date_buf
add ecx, eax; add length returned by GetDateFormat
mov byte ptr [ ecx-1 ], ' '; replace null with space
; Print Time!
invPrt: invoke GetTimeFormat, 0, NULL, \
                  ADDR stm, ADDR timeformat, ecx, 20
     invoke lstrcat, addr date_buf, addr FirstSpace

invMess: invoke MessageBox, 0,  addr pzTitle, addr date_buf, MB_OK
     invoke   MessageBox,0 , addr pzTitle, addr date_buf, MB_OK
     exit
err_tz:
     invoke    MessageBox, 0, addr pzTitle, addr TimeZoneNotSet, MB_OK
     exit
     END start
; D:\masm32\Bin\timzonw.asm


We got rid of the CR and LF it was screwing up title bar for some reason.
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge


Hi Console or Dos Box Fans:

We are still using CMD.EXE or Command.com.

For your amusement try this out.

This is showasc.asm does the same only in Dos.

; SHOWASC.ASM Tuesday, November 15, 2011 4:55:48 PM
; modified Tuesday, August 20, 2013 1:16:43 AM
; added Time Zone Code from Masm32\datetime
; Console Build Please
; by herge - Show System Date & Time
; You MUST Hit Any Key to End Process
; Other Wise SHOWASC,EXE is Still
; RUNNING!
.XCREF
.XLIST
include \masm32\include\masm32rt.inc
INCLUDE \masm32\include\DateTime.inc
INCLUDELIB \masm32\lib\DateTime.lib

.LIST
.CREF
.data
date_buf   db 260 dup (0)
           db 0
FirstSpace db " "
StdOutBuf  db 128 dup (0)
           db 0

CrLf       db 13, 10 , 0           
.code
start:
     cld    ; Direction Flag Up
     mov    esi, offset StdOutBuf
     INVOKE CurrentTimeZoneName, esi
     inc    eax
     jz     err_tz
@@:     
     lodsb
     and    al, al
     jnz    @B
       
     mov    byte ptr [ esi ] , 0
     
     mov   ecx, offset date_buf
     invoke   GetDateFormat, 0, DATE_LONGDATE, \
            0, 0, ecx, 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
     push  ecx
     mov   edx, SIZEOF date_buf
     sub   edx, eax
     invoke   GetTimeFormat, 0, 0, \
            0, 0, ecx, edx
     pop   ecx
     add   ecx, eax; add length returned by GetDateFormat
     invoke lstrcat, addr date_buf, addr FirstSpace
     invoke   StdOut, addr date_buf
     invoke   StdOut, addr CrLf
     inkey "You Must Hit Any Key i e Space Bar To END Process."
     invoke ExitProcess, 0
err_tz:
     print   "Time Zone Not Set",13,10,7
     inkey   
     invoke ExitProcess, 0
     exit
     end start
     


Enjoy! Do not walk on Rail tracks and don't have both
ears under headphones God is trying to talk to you?

Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

#7
 Hi A Clock like Program.

; REM SHOWTIMA.ASM Thursday, August 22, 2013 10:24:59 AM
; Console Build Please
; January 25, 2011 8:22 AM
; Author: Herge
; Location: Waterloo, Ontario, CANADA
.XCREF ; XCREF = NO cross Reference
.XLIST ; XLIST = NO listing - Windows.inc is kind of massive man!
    include \masm32\include\masm32rt.inc
.LIST
.CREF
.data
stm  SYSTEMTIME<>
dateformat  db " dddd, MMMM, dd, yyyy", 0
timeformat  db "hh':'mm':'ss tt ",0
date_buf db 240 dup (0)
        db 21 dup (0)
MonthNameA  equ $

wDofW       equ $
            db "Sunday ",0
            db "Monday ",0
            db "Tuesday ",0
            db "Wednesday ",0
            db "Thursday ",0
            db "Friday ",0
            db "Saturday ",0 
wMonthName  equ $
            db "January ",0
            db "February ",0
            db "March ",0
            db "April ",0
            db "May ",0
            db "Jume ",0
            db "July ",0
            db "August ",0
            db "September ",0
            db "October ",0
            db "November ",0
            db "December ",0
            db 0
DyMonth equ   $
            db "Zero ", 0
            db "One ", 0
            db "Two ", 0
            db "Three ", 0
            db "Four ", 0
            db "Five ", 0
            db "Six ", 0
            db "Seven ", 0
            db "Eight ", 0
            db "Nine ", 0
            db "Ten ", 0
            db "Eleven ", 0
            db "Twelve ", 0
            db "Thirteen ", 0
            db "Fourteen ", 0
            db "Fifteen ", 0
            db "Sixteen ", 0
            db "Seventeen ", 0
            db "Eighteen ", 0
            db "Nineteen ", 0
            db "Twenty ", 0
            db "Twenty-One ", 0
            db "Twenty-Two ", 0
            db "Twenty-Three ", 0
            db "Twenty-Four ", 0
            db "Twenty-Five ", 0
            db "Twenty-Six ", 0
            db "Twenty-Seven ", 0
            db "Twenty-Eight ", 0
            db "Twenty-Nine ", 0
            db "Thirty ", 0
            db "Thirty-Ome ", 0
            db 0
CrLf      db 13,10,0
Space   db " ",0   
             db 0     
.code

CX_TH proc
; ESI > Table
; ECX is entry in table we
; want.
; find cx_th entry in table
      test  ecx, ecx
jz cx_th_exit
dec ecx ; is it first entry
jz cx_th_exit; is first then exit
@@:
lodsb
and al,al ; is byte equal zero
jnz @B; search for zero
dec ecx
jnz @B; find cx_th zero
cx_th_exit:
; cx_th zero found exit
ret
CX_TH endp

CX_TH_Entry proc uses ecx
call CX_TH
ret
CX_TH_Entry endp

P   proc    uses    ecx ; Print to Console ESI
    invoke  StdOut, esi
    ret
P   endp

NL  proc    uses esi    ; Print CrLf to Console
    mov     esi, offset CrLf
    call    P
    ret
NL  endp

Pentry  proc    uses ecx
      call  CX_TH_Entry
      call  P
      ret
Pentry  endp

PutSpace    proc uses esi     
      mov   esi, offset Space
      call  StdOut
      ret
PutSpace    endp

start   proc    near
      invoke   GetLocalTime, addr stm; put Values in stm
      movzx    ecx, stm.wDayOfWeek
      mov      esi, offset wDofW
      call     Pentry
      movzx   ecx, word ptr stm.wDay
      mov   esi, offset DyMonth
      call  Pentry
      movzx  ecx, word ptr stm.wMonth
      mov   esi, offset wMonthName
      call  Pentry
      movzx eax, word ptr stm.wYear
      print   ustr$(eax), " "
      movzx eax, word ptr stm.wHour
      print ustr$(eax),":"
      movzx   eax, word ptr stm.wMinute
      print ustr$(eax),":"
      movzx   eax, word ptr stm.wSecond
      print ustr$(eax),32,13,10
      inkey "Hit The Space Bar to Close!"
      invoke      ExitProcess, 0
start   endp     
        end start


Note if Day of month is  greater than 31  I am Not sure
what it will print probaby some object code that will some of
graphic code so watch it. Also it uses inkey i e input from
Console so always hit the Space Bay and only Console build.
You should not ve getting 32 from Day of Month?

Directory of D:\masm32\bin

8/22/2013  10:34 AM             3,741 showtima.asm
8/22/2013  10:34 AM             3,899 showtima.exe
8/22/2013  10:34 AM           289,270 showtima.obj
8/22/2013  10:34 AM           353,280 showtima.pdb
              4 File(s)        650,190 bytes
              0 Dir(s)  131,507,875,840 bytes free

:\masm32\bin>pause
Press any key to continue . . .

:\masm32\bin>showtima
Wednesday Twenty-One August 2013 10:35:12
Hit The Sapce Bar to Close!

Enjoy!
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.