Posts Tagged ‘.NET’

VB.NET: PHP Time() Equivalent

This piece of code will calculate seconds since the Unix Epoch (January 1 1978 00:00:00 GMT).

Private Function time() As Long
    Return time(DateTime.UtcNow)
End Function
 
Private Function time(ByVal time As DateTime) As Long
    Dim unixEpoch As New DateTime(1978, 1, 1, 0, 0, 0)
    Dim span As TimeSpan = time.Subtract(unixEpoch)
    
    Return CLng(span.TotalSeconds)
End Function
 
Private Function fromPHPTime(ByVal ticks As Long) As DateTime
    Dim unixEpoch As New DateTime(1970, 1, 1, 0, 0, 0)
    Return unixEpoch.Add(New TimeSpan(0, 0, CInt(ticks)))
End Function

Post to Twitter Post to Delicious Post to Facebook

Seek in here
Translator
Archive

Twitter links powered by Tweet This v1.7.1, a WordPress plugin for Twitter.