Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Unix time <--> File time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unix time <--> File time

    Not much, but can be useful :

    Code:
    Function UnixTimeToFileTime(ByVal UnixTime As Dword) As Quad
      Function = UnixTime*10000000+116444736000000000
    End Function
    
    Function FileTimeToUnixTime(ByVal FT As Quad) As Dword
      Function = (FT - 116444736000000000) \ 10000000
    End Function
    Regards,
    Peter

  • #2
    Was having problems with the above functions... then rewrote them:

    Code:
    #Compile Exe
    #Dim All
    
    #Include "win32api.inc"
    
    Union FILETIME_DWORD_UNION_TYPE
        FT As FILETIME
        DW As Quad
    End Union
    
    Sub UnixTimeToFileTime(ByVal dwUnixTime As Dword, ByRef ftFileTime As FILETIME)
        Local TimeUnion As FILETIME_DWORD_UNION_TYPE
        TimeUnion.DW = (dwUnixTime * 10000000) + 116444736000000000
        ftFileTime = TimeUnion.FT
    End Sub
    
    Function FileTimeToUnixTime(ByRef ftFileTime As FILETIME) As Dword
        Local TimeUnion As FILETIME_DWORD_UNION_TYPE
        TimeUnion.FT = ftFileTime
        Function = (TimeUnion.DW - 116444736000000000) / 10000000
    End Function
    
    Function PBMain
    
        ' ---------------------------
        ' Converting UTC to Unix time
        ' ---------------------------
        Local dwUnixTime As Dword, ftCoordinatedTime As FILETIME
        GetSystemTimeAsFileTime(ftCoordinatedTime) ' The system time is expressed in Coordinated Universal Time (UTC)
        dwUnixTime = FileTimeToUnixTime(ftCoordinatedTime)
        ? Format$(dwUnixTime,"#,###")
    
        ' ---------------------------
        ' Converting Unix time to UTC
        ' ---------------------------
        Local systemtimeLOCAL, systemtimeUTC As SYSTEMTIME, filetimeLOCAL, filetimeUTC As FILETIME
    
        UnixTimeToFileTime(dwUnixTime,filetimeUTC)
    
        FileTimeToSystemTime(ByVal VarPtr(filetimeUTC), ByVal VarPtr(systemtimeUTC))
        ? Format$(systemtimeUTC.wYear)+"-"+Format$(systemtimeUTC.wMonth)+"-"+Format$(systemtimeUTC.wDay)+" "+Format$(systemtimeUTC.wHour)+":"+Format$(systemtimeUTC.wMinute)+":"+Format$(systemtimeUTC.wSecond)+" UTC"
    
    End Function
    
    Last edited by Jim Dunn; 10 Feb 2011, 03:04 PM.
    3.14159265358979323846264338327950
    "Ok, yes... I like pie... um, I meant, pi."

    Comment

    Working...
    X