Menu

UNIX Time and Date

jackjames
2023-03-30
2023-03-30
  • jackjames

    jackjames - 2023-03-30

    Is there an instruction or algorithm that transforms time and date into unix format and vice-versa?

     
  • Anobium

    Anobium - 2023-03-30

    Here is mije from UDP/NTP time protocol I needed it for NTP time.

    ' Routine to convert the LONG from the NTP-server in to date and time
    '
    Sub ENC28J60_NTP
        dim l1 as long
        DIM L2 AS long
    
        L1 = T_udp_data3
        L1_H = T_udp_data2
        L1_U = T_udp_data1
        L1_E   = T_udp_data0
        L1 = L1 - [Long]3660595200
        L1 = L1 + [LONG]3600 ' offset UTC - 1 hour
    
    
        HserPrint "Date "
        l2 = ( l1 / 86400 ) + 1
        HSerPrint l2
        ' Need to resolve leap years.  isleap( l1 / 31536000 )
    '    for ii = 1 to 365 + isleap( l1 / 31536000 )
    '
    '
    '    next
    
        l2 = l1 / 31536000  ' year
        l2 = l2 + 2016
        HSerPrint "D/"
        HSerPrint l2
        HSerPrintCRLF
    
    
        HserPrint "Time "
        l2 = L1 % 86400
        l2 = l2 / 3600
        if l2 < 10 then HSerPrint "0"
        HSerPrint l2
        HSerPrint ":"
        l2 = L1 % 3600
        l2 = l2 / 60
        if l2 < 10 then HSerPrint "0"
        HSerPrint l2
        l2 = L1 % [LONG]60
        HSerPrint ":"
        if l2 < 10 then HSerPrint "0"
        HSerPrint l2
        HSerPrintCRLF
    
    
    End Sub
    

    Some long number is in T_udp_data() which is loaded into L1. Magic calcs.... the time.

    I would lift the code from the NTP protocol.

     

    Last edit: Anobium 2023-03-30

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.