English
Source / code snippets

Unix time Stamp (sec since 01.01.1970) in lesbares date transfiguring

 

Sven
Bader
can the XProfan really not? too in the Forum have I only Solutions with complicated Berechnungen found. These Solution here uses The Windows API. it functions free from problems too in middle-aged XProfan versions.

UPDATE: one can now too one lesbares date in a Timestamp konvertieren

UPDATE 2: reaches go tidy released, newer XProfan versions functions now too with QuadInt and so with data over 2038 out, ältere XProfan versions receive one Fallback
Def RtlSecondsSince1970ToTime(2) !"ntdll.dll", "RtlSecondsSince1970ToTime"
Def RtlTimeToSecondsSince1970(2) !"ntdll.dll", "RtlTimeToSecondsSince1970"
Def FileTimeToSystemTime(2) !"Kernel32.dll", "FileTimeToSystemTime"
Def SystemTimeToFileTime(2) !"Kernel32.dll", "SystemTimeToFileTime"
Struct SYSTEMTIME = y%,m%,w%,d%,h%,i%,s%,millisecond%

Proc Date2UnixTime

    Parameters dateString$
    Declare systemTime#,  datePart$, timePart$, fileTime#
    Dim systemTime#, SYSTEMTIME
    Dim fileTime#,8
    datePart$ = SubStr$(dateString$,1," ")'date
    timePart$ = SubStr$(dateString$,2," ")'Uhrzeit
    systemTime#.y% = Val(SubStr$(datePart$,1,"-"))// year
    systemTime#.m% = Val(SubStr$(datePart$,2,"-"))// month
    systemTime#.d% = Val(SubStr$(datePart$,3,"-"))// day
    systemTime#.h% = Val(SubStr$(timePart$,1,":"))// hour
    systemTime#.i% = Val(SubStr$(timePart$,2,":"))// Minute
    systemTime#.s% = Val(SubStr$(timePart$,3,":"))// second
    systemTime#.millisecond% = 0// Millisekunde
    SystemTimeToFileTime(systemTime#, fileTime#)
     $IFDEF VER12.0
    Declare Quad unixTimeQuad
    RtlTimeToSecondsSince1970(fileTime#, Addr(unixTimeQuad))
    Dispose fileTime#, systemTime#
    Return unixTimeQuad
     $ELSE
    'deference Quadint, the functions only To 2038!
    Declare unixTime&, unixTime#
    Dim unixTime#,8
    RtlTimeToSecondsSince1970(fileTime#,unixTime#)
    unixTime& = Long(unixTime#,0)
    Dispose fileTime#, systemTime#, unixTime#
    Return unixTime&
     $ENDIF

ENDPROC

Proc UnixTime2Date

    Parameters fileTime&
    Declare fileTime#, t#, output$
    Dim fileTime#,8
    Dim t#, SYSTEMTIME
    RtlSecondsSince1970ToTime(fileTime&, fileTime#)
    FileTimeToSystemTime(fileTime#, t#)
    output$ =  Str $( t#.d%) + "." + Str $(t#.m%)   +"." + Str $(t#.y%)  + " " +   Str $(t#.h%) + ":" + Str $(t#.i%) +":" + Str $(t#.s%)
    Dispose t#, fileTime#
    Return  output$

ENDPROC

Cls
Print UnixTime2Date(2504776539)
Print Date2UnixTime("2049-05-16 11:15:39")
WaitKey
End
 
05/16/24  
 




Georg
Teles
interestingly,

functions free from problems with 8, 10, x2 and x4 In any drop
 
Alle Sprachen
TC-Programming [...] 
XProfan 8.0 - 10.0 - X2 - X3 - X4

05/23/24  
 




Jens-Arne
Reumschüssel
Hi,

very interestingly! Can certainly time well use.

small Note: i don't know, whether it so well is, Zeiger on pub declared Memory-Variables as Proc-Results zurückzugeben. The go so nirgends More disposed (=Speicherleck, anyway at least during the Programmlaufzeit, sofern XProfan or windows the at End of program behebt, otherwise permanent, To the computer new launched becomes).

best Regards, Jens-Arne
 
XProfan X4
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/05/24  
 




Sven
Bader
UPDATE: The neuste Version is in the Original-Posting integrally supra!

thanks for the Feedback Jens-Arne!

I found The Zwischenschritte as function integrally nice but letztendlich need one tappt im dunkeln not and it'll lesbarer and leichter To use without:
Def RtlSecondsSince1970ToTime(2) !"ntdll.dll", "RtlSecondsSince1970ToTime"
Def RtlTimeToSecondsSince1970(2) !"ntdll.dll", "RtlTimeToSecondsSince1970"
Def FileTimeToSystemTime(2) !"Kernel32.dll", "FileTimeToSystemTime"
Def SystemTimeToFileTime(2) !"Kernel32.dll", "SystemTimeToFileTime"
Struct SYSTEMTIME = y%,m%,w%,d%,h%,i%,s%,millisecond%

Proc FileTimeToUnixTime

    Parameters dateString$
    Declare systemTime#,  datePart$, timePart$, fileTime#, filetime&, unixTime&, unixTime#
    Dim systemTime#, SYSTEMTIME
    Dim fileTime#,8
    Dim unixTime#,8
    datePart$ = SubStr$(dateString$,1," ")'date
    timePart$ = SubStr$(dateString$,2," ")'Uhrzeit
    systemTime#.y% = Val(SubStr$(datePart$,1,"-"))// year
    systemTime#.m% = Val(SubStr$(datePart$,2,"-"))// month
    systemTime#.d% = Val(SubStr$(datePart$,3,"-"))// day
    systemTime#.h% = Val(SubStr$(timePart$,1,":"))// hour
    systemTime#.i% = Val(SubStr$(timePart$,2,":"))// Minute
    systemTime#.s% = Val(SubStr$(timePart$,3,":"))// second
    systemTime#.millisecond% = 0// Millisekunde
    SystemTimeToFileTime(systemTime#, fileTime#)
    RtlTimeToSecondsSince1970(fileTime#, unixTime#)
    'deference Quadint, the functions only To 2038!
    unixTime& = Long(unixTime#,0)
    Dispose fileTime#, systemTime#, unixTime#
    Return unixTime&

ENDPROC

Proc FileTimeToReadable

    Parameters fileTime&
    Declare fileTime#, t#, output$
    Dim fileTime#,8
    Dim t#, SYSTEMTIME
    RtlSecondsSince1970ToTime(fileTime&, fileTime#)
    FileTimeToSystemTime(fileTime#, t#)
    output$ =  Str $( t#.d%) + "." + Str $(t#.m%)   +"." + Str $(t#.y%)  + " " +   Str $(t#.h%) + ":" + Str $(t#.i%) +":" + Str $(t#.s%)
    Dispose t#, fileTime#
    Return  output$

ENDPROC

Cls
Print FileTimeToReadable(1715858139)
Print FileTimeToUnixTime("2024-05-16 11:15:39")
Waitkey
End
 
07/05/24  
 




Jens-Arne
Reumschüssel
the sees but already correctly. well from!

one can naturally one Quad take, circa too in 15 years still in the process To his:

Declare Quad unixTimeQuad
RtlTimeToSecondsSince1970(fileTime#, Addr(unixTimeQuad))
Return unixTimeQuad
 
XProfan X4
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/06/24  
 




Sven
Bader
thanks! I have your suggestion with Compiler-Weiche for newer XProfan versions übernommen and my by the latest Update misleading Funktionsnamen changed. The code is in the Original-Posting. because of of performance and the Profan2Cpp compatibility slopes I mostly self yet on XProfan 11 solid.
 
07/06/24  
 




Jens-Arne
Reumschüssel
I have time a small DLL for Use of QuadInts in XProfan To Version 11 written, see here:  [...] 

so ought to one too for ältere Profan-versions your lovely UnixTime-code zukunftsfähig make can. it'll Yes überwiegend circa compare of such times weg, and the can The DLL free from problems manage.
 
XProfan X4
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/06/24  
 




Jens-Arne
Reumschüssel
here a Version, The for old Profane QuadInt.dll uses. the has too whom benefit, that the Result not negative displayed becomes (LongInt is to to that last bit ausgenutzt and XProfan nunmal signed), what to Visualisierung the sec since the 01.01.1970 not helpful is.
 $IFNDEF VER12.0
 $I QuadInt.inc
 $ENDIF
Def RtlSecondsSince1970ToTime(2) !"ntdll.dll", "RtlSecondsSince1970ToTime"
Def RtlTimeToSecondsSince1970(2) !"ntdll.dll", "RtlTimeToSecondsSince1970"
Def FileTimeToSystemTime(2) !"Kernel32.dll", "FileTimeToSystemTime"
Def SystemTimeToFileTime(2) !"Kernel32.dll", "SystemTimeToFileTime"
Struct SYSTEMTIME = y%,m%,w%,d%,h%,i%,s%,millisecond%

Proc Date2UnixTime

    Parameters dateString$
    Declare systemTime#,  datePart$, timePart$, fileTime#
    Dim systemTime#, SYSTEMTIME
    Dim fileTime#,8
    datePart$ = SubStr$(dateString$,1," ")'date
    timePart$ = SubStr$(dateString$,2," ")'Uhrzeit
    systemTime#.y% = Val(SubStr$(datePart$,1,"-"))// year
    systemTime#.m% = Val(SubStr$(datePart$,2,"-"))// month
    systemTime#.d% = Val(SubStr$(datePart$,3,"-"))// day
    systemTime#.h% = Val(SubStr$(timePart$,1,":"))// hour
    systemTime#.i% = Val(SubStr$(timePart$,2,":"))// Minute
    systemTime#.s% = Val(SubStr$(timePart$,3,":"))// second
    systemTime#.millisecond% = 0// Millisekunde
    SystemTimeToFileTime(systemTime#, fileTime#)
     $IFDEF VER12.0
    Declare Quad unixTimeQuad
    RtlTimeToSecondsSince1970(fileTime#, Addr(unixTimeQuad))
    Dispose fileTime#, systemTime#
    Return unixTimeQuad
     $ELSE
    'deference Quadint, the functions only To 2038!
    Declare unixTime&, unixTime#
    Dim unixTime#,8
    RtlTimeToSecondsSince1970(fileTime#,unixTime#)
    RtlTimeToSecondsSince1970(fileTime#,QuadAddr(1))
    unixTime& = Long(unixTime#,0)
    Dispose fileTime#, systemTime#, unixTime#
    Return unixTime&
     $ENDIF

ENDPROC

Proc UnixTime2Date

    Parameters fileTime&
    Declare fileTime#, t#, output$
    Dim fileTime#,8
    Dim t#, SYSTEMTIME
    RtlSecondsSince1970ToTime(fileTime&, fileTime#)
    FileTimeToSystemTime(fileTime#, t#)
    output$ =  Str $( t#.d%) + "." + Str $(t#.m%)   +"." + Str $(t#.y%)  + " " +   Str $(t#.h%) + ":" + Str $(t#.i%) +":" + Str $(t#.s%)
    Dispose t#, fileTime#
    Return  output$

ENDPROC

Cls
Print UnixTime2Date(2504776539)
 $IFDEF VER12.0
Print Date2UnixTime("2049-05-16 11:15:39")
 $ELSE
InitQuadInt(1)
Date2UnixTime("2049-05-16 11:15:39")
Print QuadGetStr(1)
 $ENDIF
WaitKey
End
 
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
07/07/24  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

790 Views

Untitledvor 0 min.
Sven Bader vor 30 Tagen
HofK10/09/24
Manfred Barei09/25/24
Gast.081508/21/24
More...

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie