The MASM Forum

General => The Campus => Topic started by: jj2007 on September 20, 2015, 08:07:45 PM

Title: Current time plus X seconds - simple example
Post by: jj2007 on September 20, 2015, 08:07:45 PM
GetTimePlusX works with plain Masm32, but you will need a replacement for MasmBasic's fTime$() macro (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1268):

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
.code
GetTimePlusX proc xtra
LOCAL stime:SYSTEMTIME, ftime:FILETIME
  invoke GetLocalTime, addr stime
  invoke SystemTimeToFileTime, addr stime, addr ftime
  fild xtra                  ; put xtra into ST(0)
  fmul FP4(10000000.0)       ; convert to seconds (i.e. adjust for 100-nanosecond intervals)
  fild qword ptr ftime
  fadd
  fistp qword ptr ftime
  movlps xmm0, ftime
  ret
GetTimePlusX endp

  Init
  PrintLine fTime$()             ; current time
  invoke GetTimePlusX, 1800      ; plus 30 minutes
  PrintLine fTime$(xmm0)
  invoke GetTimePlusX, 3600*5    ; plus 5 hours
  PrintLine fTime$(xmm0)
  Exit

end start

Output:
12:00:14
12:30:14
17:00:14
Title: Re: Current time plus X seconds - simple example
Post by: ragdog on September 20, 2015, 09:49:46 PM
Hello Jochen

Nice Snipped  ;)
Title: Re: Current time plus X seconds - simple example
Post by: dedndave on September 21, 2015, 12:01:03 AM
        INCLUDE    \Masm32\Include\Masm32rt.inc

        .DATA?
        ALIGN   4

fts     FILETIME <>
sts     SYSTEMTIME <>
buf     db 32 dup(?)

        .CODE

main    PROC

;get the local time in a SYSTEMTIME structure

        INVOKE  GetLocalTime,offset sts

;format the time for display, and show it

        INVOKE  GetTimeFormat,LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT or TIME_NOTIMEMARKER,
                offset sts,NULL,offset buf,sizeof buf
        print   offset buf,13,10

;convert SYSTEMTIME to FILETIME

        INVOKE  SystemTimeToFileTime,offset sts,offset fts

;add 1 minute

        add     fts.dwLowDateTime,600000000  ;1 minute, in 100 nS steps
        adc     fts.dwHighDateTime,0

;convert FILETIME to SYSTEMTIME

        INVOKE  FileTimeToSystemTime,offset fts,offset sts

;format the time for display, and show it

        INVOKE  GetTimeFormat,LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT or TIME_NOTIMEMARKER,
                offset sts,NULL,offset buf,sizeof buf
        print   offset buf,13,10

        print   chr$(13,10)
        inkey
        INVOKE  ExitProcess,0

main    ENDP

        END     main
Title: Re: Current time plus X seconds - simple example
Post by: herge on September 30, 2015, 07:49:32 AM

Hello Jochen & Dave:

If we use an offset of say UTC -12 or UTC -14
we could have all positive offsets.
We could be sneaky and pound out 24 hours from UTC-12
in one hour intervals. If we use an offset of (systemtime+15),or
filetime+15, you would have daylight savings time?
I am assuming of course that daylight savings time is plus one hour
over standard time. We still have N Korea, Venezuela, India, Nepal
and Newfoundland and some Australian states that are half hour
and of course New Zealand's Chatham islands +45 minutes.

Regards Herge
Title: Re: Current time plus X seconds - simple example
Post by: dedndave on September 30, 2015, 07:14:43 PM
rather than do that, use a time zone near the international date line as the base-zone   :biggrin:
Title: Re: Current time plus X seconds - simple example
Post by: rrr314159 on September 30, 2015, 08:03:19 PM
Quote from: herge... of course New Zealand's Chatham islands +45 minutes.

- of course! everybody knows that :P
Title: Re: Current time plus X seconds - simple example
Post by: dedndave on September 30, 2015, 09:24:22 PM
in days past, many areas in Russia used 15 minute increments (and other parts of Eurasia)
i seem to recall that some even had 20 and 40 - but, i can't find any historical info to support that

the only reason i know anything about it is ham radio - lol
i got my first license at age 12 (early 1968), so i've noticed a few changes
Title: Re: Current time plus X seconds - simple example
Post by: TWell on September 30, 2015, 09:35:37 PM
Now russian have 1 hour intervals. Least here (https://en.wikipedia.org/wiki/Time_in_Russia)
That CCCP (sssr) time is over :t
Title: Re: Current time plus X seconds - simple example
Post by: herge on October 01, 2015, 05:27:46 AM
Good Afternoon TWell:

Just Google "Time in Wherever"
where Wherever is a city or country you
are intrested in.

Regards Herge
Title: Re: Current time plus X seconds - simple example
Post by: herge on October 07, 2015, 08:52:54 PM

Good Morning Dave:

https://en.wikipedia.org/wiki/International_Date_Line (https://en.wikipedia.org/wiki/International_Date_Line)

UTC-12 or UTC+12 will get you near the international date line.

Regards Herge