¿Hay alguna función en punto net vb para convertir fecha y hora a la marca de tiempo Unix Si I Google consigo sólo el viceversa, pero no a VB.NET marca de tiempo UnixDateTime a unixtime sello en .net
Cualquier ayuda se aprecia
¿Hay alguna función en punto net vb para convertir fecha y hora a la marca de tiempo Unix Si I Google consigo sólo el viceversa, pero no a VB.NET marca de tiempo UnixDateTime a unixtime sello en .net
Cualquier ayuda se aprecia
{Editar} eliminado antiguo enlace de referencia
segundos desde ene 1, 1970 = tiempo Unix
Para conseguir esto en VB.NET ejemplo véase más adelante (en el ejemplo usando DateTime.UtcNow, pero puede conectar cualquier DateTime que desee re)
Dim uTime As Integer
uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
En cuanto a http://www.codeproject.com/KB/cs/timestamp.aspx muestra UNIX -> red para que pueda ir hacia atrás lo más probable:.
DateTime dt = "the date";
DateTime start= new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan ts = (dt - start);
ts.TotalSeconds //unix timestamp
o algo similar lo hará.
nota, esto no ha sido probado por mi trabajo por lo que probablemente no :)
escribí estos en algún momento - todo similar a la anterior sólo con un poco más de detalle en el que el ajuste del tiempo de verano para edad yo aquí en el Reino Unido.
Public Function UnixToTime(ByVal strUnixTime As String) As Date
UnixToTime = DateAdd(DateInterval.Second, Val(strUnixTime), #1/1/1970#)
If UnixToTime.IsDaylightSavingTime = True Then
UnixToTime = DateAdd(DateInterval.Hour, 1, UnixToTime)
End If
End Function
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
En javascript, al menos, las marcas de tiempo de unix son milisegundos, y encontré un caso donde las necesitaba. Este código hace uso de .Net usando 10,000 ticks/milisegundo. Aquí está el código que utilicé:
Public Module UnixTime
Const UnixEraStartTicks As Long = 621355968000000000
<Extension> Public Function UnixTimestamp(value As Date) As Long
Dim UnixEraTicks = value.Ticks - UnixEraStartTicks
Return UnixEraTicks \ 10000
End Function
Public Function DateFromUnix(timestamp As Long) As Date
Return New Date(UnixEraStartTicks + timestamp * 10000)
End Function
End Module
Este enlace está roto. ¿Podría actualizar el enlace e incluir los contenidos en su respuesta? – Matt
Efectivamente, 3 años después y el enlace está roto, actualizando la respuesta con el código de ejemplo – curtisk
Versión de Const: (DateTime.UtcNow - # 1/1/1970 #). TotalSeconds - Además, utilice un Int64 o se ajustará en el año 2038. Similar al problema de y2k. – Brain2000