简体   繁体   中英

PHP's Microtime(true) Equivalent For VB.NET?

I am trying to regenerate PHP's microtime(true) in VB.NET to create a microtime (1344004866.8658) although I am not having much luck!

I have searched all over the net & cannot seem to find any help around for this one!

I am using the following function to create a standard Unix timestamp:

Public Function TimeToUnix(ByVal dteDate As Date) As String
        If dteDate.IsDaylightSavingTime = True Then
            dteDate = DateAdd(DateInterval.Hour, -1, dteDate)
        End If
        TimeToUnix = DateDiff(DateInterval.Second, #1/1/1970#, dteDate)
    End Function

Although am completely lost as to how I would change this function to create a microtime!

Any help would be much appretiated :-)

Ah, finally found something & ammended it for daylight saving which helped:

Public Function GetUnixMicroTime(ByVal dates As DateTime) As String
        If dates.IsDaylightSavingTime = True Then
            dates = DateAdd(DateInterval.Hour, -1, dates)
        End If
        Dim origin As DateTime = New DateTime(1970, 1, 1, 0, 0, 0, 0)
        Dim diff As TimeSpan = dates - origin
        Return CStr(diff.TotalSeconds)
    End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM