Getting GMT as Unix Epoch in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #1

    Getting GMT as Unix Epoch in VB.NET

    Hi:
    I have to convert a data (not the current date) to GMT and represent it as a Unix Epoch.

    This is what I'm trying - it returns something that looks correct - but I'd like to know if anyone with more experience knows if I am doing this correctly.

    Code:
    Friend Function GetEpoch(ByVal dDate as Date) as Integer
    
    Return (dDate.ToFileTimeUtc - New DateTime(1970, 1, 1, 0, 0, 0, 0).ToFileTimeUtc) / 10000000
    
    End Function
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Hmm, I am not sure why you go to filetime and divide by that large number, but if it works, it works?

    If I did it in c# (and in a non-condensed way)
    [code=c#]
    public long GetEpoch(DateTi me dDate)
    {
    DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Ut c);
    DateTime myUTC = dDate.ToUnivers alTime();
    return ((DateTime)(myU TC - epoch)).Ticks;
    }
    [/code]

    Comment

    Working...