flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to convert from number of milliseconds since Jan 1, 1970 |
Author |
|
vid 03 Aug 2007, 09:22
Quote: PS: and vid if you think this thread does not belong here move it at your own will! Yes, i think your question is Windows-specific (because you mention API functions). Let me know if I am wrong. |
|||
03 Aug 2007, 09:22 |
|
0.1 03 Aug 2007, 09:34
I did not mean Win32API although but anyway it's ok here.
I want the reply and you decide the right place for the thread. Hope it's not too much work for you! |
|||
03 Aug 2007, 09:34 |
|
vid 03 Aug 2007, 09:51
nope, just few seconds.
In case you like to use libc, see http://msdn2.microsoft.com/en-us/library/z54t9z5f(VS.80).aspx |
|||
03 Aug 2007, 09:51 |
|
0.1 04 Aug 2007, 10:15
sec = msec / 1000
min = sec / 60 hr = min / 60 day = hr / 24 mon = day / 30 or 31 or 28 or 29 year = mon / 12 _________________ Code: o__=- ) (\ /\ Last edited by 0.1 on 04 Aug 2007, 10:44; edited 1 time in total |
|||
04 Aug 2007, 10:15 |
|
vid 04 Aug 2007, 10:32
don't forget overlapping years
|
|||
04 Aug 2007, 10:32 |
|
0.1 04 Aug 2007, 10:42
I know above is wrong!
Just posted it so that some one adds the correction here! _________________ Code: o__=- ) (\ /\ |
|||
04 Aug 2007, 10:42 |
|
MHajduk 04 Aug 2007, 12:20
0.1 wrote: sec = msec / 1000 Code: sec / 1000 = msec min / 60 = sec hr /60 = min day / 24 = hr mon / (30 or 31 or 28 or 29) = day year / 12 = mon |
|||
04 Aug 2007, 12:20 |
|
0.1 04 Aug 2007, 12:37
No MHajduk!
I am confused about my 5th line? |
|||
04 Aug 2007, 12:37 |
|
zann 04 Aug 2007, 19:15
const
MsecPerDay=86400E3 MsecPerYear=MSecPerDay*365 MsecPerLeapYear=MSecPerDay*366 :IsLeapYear (Year is in eax) mov edx,eax and edx,$FFFFFF3 cmp eax,edx jne @@No ;not divisible by 4 mov ecx,eax xor edx,edx div dword(100) test edx,edx ;not a century jnz @@yes mov edx,eax and edx,$FFFFFF3 ;year/100/4 also a leap year cmp edx,eax je @@yes @@No:xor eax,eax ret @@Yes:Mov eax,1 |
|||
04 Aug 2007, 19:15 |
|
handyman 04 Aug 2007, 20:03
Original requst also stated a starting point of Jan 1, 1970, so there will have to be an adjustment made somewhere in logic to handle this offset so that the math works out (year 2000 a leap year). Also month and day of month calculations can be handled by lookup table or series of month length subtractions since the days of month are not all the same. And do not forget the February length leap year calculation that usually ends up in the middle of all this.
|
|||
04 Aug 2007, 20:03 |
|
r22 05 Aug 2007, 01:09
Here's the actual code that will do what you want.
It can be improved by using ... -A larger LUT -Dividing the INPUT by 365.25 * 1000*60*60*24 and floor to get the year then working from their for the other values -Unrolling the loops -Using the proper api and not worrying about this stuff It's untested since I wrote it in the browser, sorry if it doesnt work, but it should at least show you the algorithm Code: .data DAYMS = 1000 * 60 * 60 * 24 HOURMS = 1000 * 60 * 60 MINUTEMS = 1000 * 60 SECONDMS = 1000 MON28 = DAYMS * 28 MON29 = DAYMS * 29 MON30 = DAYMS * 30 MON31 = DAYMS * 31 YRS_LUT_SIZE = 4 YRS_LUT: dq DAYMS*366, DAYMS*365, DAYMS*365, DAYMS*365 LEAP_LUT: dq MON31, MON29, MON31, MON30, MON31, MON30, MON31, MON31, MON30, MON31, MON30, MON31 REG_LUT: dq MON31, MON28, MON31, MON30, MON31, MON30, MON31, MON31, MON30, MON31, MON30, MON31 INPUT dq 0 ;; put the milli seconds since 1970 here ;;Returned values YEAR dd 0 MONTH dd 0 DAY dd 0 HOUR dd 0 MINUTE dd 0 SECOND dd 0 MILLISSECOND dd 0 .code GET_DATE_INFO: PUSH ebp MOV ebp,esp MOV eax,[INPUT] ;;low 32bits of 64bit ms since 1970 MOV edx,[INPUT+4] ;;high 32bits MOV ecx,1970 ;;start year XOR ebx,ebx ;;YRS_LUT index .GETYR: MOV esi, [YRS_LUT + ebx * 8] ;; low 32bit MOV edi, [YRS_LUT + ebx * 8 + 4] ;; high 32 bit CMP edx,edi ;; add another year or not JA .SKIPYR JB .ENDYR CMP eax,esi JB .ENDYR .SKIPYR: SUB eax,esi SBB edx,edi INC ecx INC ebx AND ebx,3 ;;replaces CMP ebx, YRS_LUT_SIZE JMP .GETYR .ENDYR: MOV [YEAR], ecx MOV ecx,1 ;; start month TEST ebx,ebx ;; iF leap year CMOVNE ebx,REG_LUT CMOVE ebx,LEAP_LUT .GETMO: MOV esi, [ebx] ;; low 32bit MOV edi, [ebx + 4] ;; high 32 bit CMP edx,edi ;; add another month or not JA .SKIPMO JB .ENDMO CMP eax,esi JB .ENDMO .SKIPMO: SUB eax,esi SBB edx,edi INC ecx ADD ebx,8 JMP .GETMO .ENDMO: MOV [MONTH], ecx .GETDAY: MOV ecx,DAYMS DIV ecx INC eax ;; correct for One instead of Zero indexing of values MOV [DAY], eax .GETHR: MOV eax,edx MOV ecx,HOURMS XOR edx,edx DIV ecx INC eax ;; ;;PUT AM/PM CODE HERE ;; MOV [HOUR],eax .GETMIN: MOV eax,edx MOV ecx,MINUTEMS XOR edx,edx DIV ecx MOV [MINUTE],eax .GETSEC: MOV eax,edx MOV ecx,SECONDMS XOR edx,edx DIV ecx MOV [SECOND],eax .GETMS: MOV [MILLISECOND],edx MOV esp,ebp POP ebp RET 0 |
|||
05 Aug 2007, 01:09 |
|
0.1 05 Aug 2007, 03:47
Thanks a lot zann, r22 and handyman!
|
|||
05 Aug 2007, 03:47 |
|
Vasilev Vjacheslav 10 Aug 2007, 15:36
this thing (How to convert from number of milliseconds since Jan 1, 1970) called unix_time
http://en.wikipedia.org/wiki/Unix_time |
|||
10 Aug 2007, 15:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.