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

  • Jim Dunn
    replied
    Was having problems with the above functions... then rewrote them:

    Code:
    [font=Consolas][color=#0000FF]#Compile Exe[/color]
    [color=#0000FF]#Dim All[/color]
    
    [color=#0000FF]#Include[/color] [color=#FF0000]"win32api.inc"[/color]
    
    [color=#0000FF]Union[/color] FILETIME_DWORD_UNION_TYPE
        FT [color=#0000FF]As[/color] FILETIME
        DW [color=#0000FF]As Quad[/color]
    [color=#0000FF]End Union[/color]
    
    [color=#0000FF]Sub[/color] UnixTimeToFileTime[color=#FF0000]([/color][color=#0000FF]ByVal[/color] dwUnixTime [color=#0000FF]As Dword[/color], [color=#0000FF]ByRef[/color] ftFileTime [color=#0000FF]As[/color] FILETIME[color=#FF0000])[/color]
        [color=#0000FF]Local[/color] TimeUnion [color=#0000FF]As[/color] FILETIME_DWORD_UNION_TYPE
        TimeUnion.DW [color=#FF0000]=[/color] [color=#FF0000]([/color]dwUnixTime [color=#FF0000]*[/color] [color=#400000]10000000[/color][color=#FF0000])[/color] [color=#FF0000]+[/color] [color=#400000]116444736000000000[/color]
        ftFileTime [color=#FF0000]=[/color] TimeUnion.FT
    [color=#0000FF]End Sub[/color]
    
    [color=#0000FF]Function[/color] FileTimeToUnixTime[color=#FF0000]([/color][color=#0000FF]ByRef[/color] ftFileTime [color=#0000FF]As[/color] FILETIME[color=#FF0000])[/color] [color=#0000FF]As Dword[/color]
        [color=#0000FF]Local[/color] TimeUnion [color=#0000FF]As[/color] FILETIME_DWORD_UNION_TYPE
        TimeUnion.FT [color=#FF0000]=[/color] ftFileTime
        [color=#0000FF]Function[/color] [color=#FF0000]=[/color] [color=#FF0000]([/color]TimeUnion.DW [color=#FF0000]-[/color] [color=#400000]116444736000000000[/color][color=#FF0000])[/color] [color=#FF0000]/[/color] [color=#400000]10000000[/color]
    [color=#0000FF]End Function[/color]
    
    [color=#0000FF]Function PBMain[/color]
    
        [color=#008000]' ---------------------------[/color]
        [color=#008000]' Converting UTC to Unix time[/color]
        [color=#008000]' ---------------------------[/color]
        [color=#0000FF]Local[/color] dwUnixTime [color=#0000FF]As Dword[/color], ftCoordinatedTime [color=#0000FF]As[/color] FILETIME
        [color=#8000FF]GetSystemTimeAsFileTime[/color][color=#FF0000]([/color]ftCoordinatedTime[color=#FF0000])[/color] [color=#008000]' The system time is expressed in Coordinated Universal Time (UTC)[/color]
        dwUnixTime [color=#FF0000]=[/color] FileTimeToUnixTime[color=#FF0000]([/color]ftCoordinatedTime[color=#FF0000])[/color]
        [color=#0000FF]? Format$[/color][color=#FF0000]([/color]dwUnixTime,[color=#FF0000]"#,###"[/color][color=#FF0000])[/color]
    
        [color=#008000]' ---------------------------[/color]
        [color=#008000]' Converting Unix time to UTC[/color]
        [color=#008000]' ---------------------------[/color]
        [color=#0000FF]Local[/color] systemtimeLOCAL, systemtimeUTC [color=#0000FF]As[/color] SYSTEMTIME, filetimeLOCAL, filetimeUTC [color=#0000FF]As[/color] FILETIME
    
        UnixTimeToFileTime[color=#FF0000]([/color]dwUnixTime,filetimeUTC[color=#FF0000])[/color]
    
        [color=#8000FF]FileTimeToSystemTime[/color][color=#FF0000]([/color][color=#0000FF]ByVal VarPtr[/color][color=#FF0000]([/color]filetimeUTC[color=#FF0000])[/color], [color=#0000FF]ByVal VarPtr[/color][color=#FF0000]([/color]systemtimeUTC[color=#FF0000])[/color][color=#FF0000])[/color]
        [color=#0000FF]? Format$[/color][color=#FF0000]([/color]systemtimeUTC.wYear[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]"[color=#FF0000]-[/color]"[/color][color=#FF0000]+[/color][color=#0000FF]Format$[/color][color=#FF0000]([/color]systemtimeUTC.wMonth[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]"[color=#FF0000]-[/color]"[/color][color=#FF0000]+[/color][color=#0000FF]Format$[/color][color=#FF0000]([/color]systemtimeUTC.wDay[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]" "[/color][color=#FF0000]+[/color][color=#0000FF]Format$[/color][color=#FF0000]([/color]systemtimeUTC.wHour[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]":"[/color][color=#FF0000]+[/color][color=#0000FF]Format$[/color][color=#FF0000]([/color]systemtimeUTC.wMinute[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]":"[/color][color=#FF0000]+[/color][color=#0000FF]Format$[/color][color=#FF0000]([/color]systemtimeUTC.wSecond[color=#FF0000])[/color][color=#FF0000]+[/color][color=#FF0000]" UTC"[/color]
    
    [color=#0000FF]End Function[/color]
    [/font]
    Last edited by Jim Dunn; 10 Feb 2011, 02:04 PM.

    Leave a comment:


  • Peter Lameijn
    started a topic Unix time <--> File time

    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
Working...
X