Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 2
Ir a la página 1, 2  Siguiente
 
Tiempo Unix Y Problema Del Año 2038
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje Tiempo Unix Y Problema Del Año 2038 
 
Buenas!.

Creo que es interesante:

Citar:

Tiempo Unix o Tiempo POSIX es un sistema para la descripción de instantes de tiempo: se define como la cantidad de segundos transcurridos desde la medianoche UTC del 1 de enero de 1970, sin contar segundos intercalares.


Tiempo Unix

Hice una pequeña función para conocer los segundos desde esa fecha.  

Public Function SegundosDesdeEpoch() As Float ''Devuelve segundos desde la fecha 1 de Enero de 1970
  
  Return DateDiff("01/01/1970", Now, gb.Second)
  
End
 


Pero no me devuelve decimales como ocurre en Python con la función:  
print (time.time())
 


Imaginar que quisierais saber los milisegundos desde la fecha del tiempo Unix!!!. A ver si podéis lograrlo.  
Con el tipo Float me da desbordamiento y con Long igual.  

Problema del año 2038

Saludos
 




===================
Gambas Básico
"No es un bug, es una característica no documentada"
 
última edición por Shell el Martes, 03 Abril 2018, 23:48; editado 1 vez 
Shell - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Shell escribió: [Ver mensaje]
Pero no me devuelve decimales...

Imaginar que quisierais saber los milisegundos desde la fecha del tiempo Unix!!!. A ver si podéis lograrlo.


Al usar " gb.Millisecond " me da error: " Overflow " !    
 



 
última edición por vuott el Viernes, 06 Abril 2018, 10:17; editado 1 vez 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Uhmmm......y esta solución ?

Return CFloat(DateDiff(CDate("01/01/1970"), Now, gb.Second)) + CFloat(Format(Now, ".uu"))
  
      img-5745426b4b
 



 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Vuott:

Citar:

Uhmmm......y esta solución ?


Es algo extraña la unión al principio, pero funciona correctamente.  
Solo devuelve un máximo de tres decimales.
¿ Algún motivo por el cual usaste ".uu" y no solo ".u" ?. Parece que no se pueden añadir más de tres milisegundos.  

Citar:

u     Print a point and the milliseconds, if they are different from zero.
uu     Print a point and the milliseconds with three digits.


Public Sub Main()
  
  Print SegundosDesdeEpoch()
  Print Epoch2()
  
End

Public Function SegundosDesdeEpoch() As Float ''Devuelve segundos desde la fecha 1 de Enero de 1970
  
  Return DateDiff("01/01/1970", Now, gb.Second)
  
End

Public Function Epoch2() As String
  
  Return CFloat(DateDiff(CDate("01/01/1970"), Now, gb.Second)) + CFloat(Format(Now, ".uu"))
  
End
 


Salida:
Citar:

1522843142
1522843142.937


Cuando la función devuelve cadena, usa el punto. Si devolviese un tipo Float, usa la coma.
Supongo que depende del país. Lógicamente me interesa tipo número, no una cadena.

 pythontimeepoch

Jo, jo, jo.  

En C:

https://www.epochconverter.com/programming/c

A ver cuantos decimales dará.  

Saludos
 




===================
Gambas Básico
"No es un bug, es una característica no documentada"
 
última edición por Shell el Miercoles, 04 Abril 2018, 09:19; editado 2 veces 
Shell - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Ahora los chicos malos gracias a que has añadido milisegundos a la función se controlan mejor!.  

 chicosmalos

Public Sub Timer1_Timer()
  
  Dim nuevoalien As Alien
  
  If SegundosDesdeEpoch() - AnteriorTiempoEnAparecer > 0.5 Then
    nuevoalien = New Alien(IMAGEN_TIO_MALO, Pantalla)  
    tiosmalos.Add(nuevoalien)
    AnteriorTiempoEnAparecer = SegundosDesdeEpoch()
  Endif
  Pantalla.Refresh
  
End
 


Saludos
 




===================
Gambas Básico
"No es un bug, es una característica no documentada"
 
Shell - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Nuestro amigo Gianluigi, del foro italiano de gambas, sugiere que usas el metodo " .ToUnixTime( ) " de la Clase Date, pero activando el Componente gb.util de Gambas.

Return CFloat(Date.ToUnixTime(Now)) + CFloat(Format(Now, ".uu"))

 



 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Shell escribió: [Ver mensaje]
Pero no me devuelve decimales como ocurre en Python con la función:  
print (time.time())
 



Puedes usar:


 



 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Shell escribió: [Ver mensaje]
En C:

https://www.epochconverter.com/programming/c

A ver cuantos decimales dará.


....MICROsegundos:    

http://www.gambas-it.org/wiki/index...del_API_di_GLIB


...o si prefieres un codigo más breve:
Library "libc:6"

Public Struct timeval
  tv_sec As Long
  tv_usec As Long
End Struct

' int gettimeofday (struct timeval *__restrict __tv, __timezone_ptr_t __tz)
' Get the current time of day and timezone information.
Private Extern gettimeofday(__tv As Timeval, __tz As Pointer) As Integer


Public Sub Main()
  
  Dim ct As New Timeval
  
  gettimeofday(ct, 0)
  
  Print ct.tv_sec; ".\e[31m"; ct.tv_usec; "\e[0m"
  
End


 
 



 
última edición por vuott el Miercoles, 04 Abril 2018, 16:32; editado 4 veces 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Segun Wiki el problema del año 2038 se soluciona pasando todo a 64bits

"La mayoría de sistemas operativos para arquitecturas de 64 bits utilizan enteros de 64 bits para time_t. La migración a estos sistemas está todavía en proceso y se espera que se complete mucho antes de 2038. Usar un entero de 64 bits retrasaría la fecha del problema unos 2,90 billones de años (2,9 × 1012). Es decir, 220 veces la edad aproximada del Universo."
 



 
tercoIDE - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Tiempo Unix Y Problema Del Año 2038 
 
Shell escribió: [Ver mensaje]
En C:

https://www.epochconverter.com/programming/c

A ver cuantos decimales dará.


Claro que tú  prefieres los... NANOsegundos:

Library "libc:6"

Public Struct timespec
  tv_sec As Long
  tv_nsec As Long
End Struct

Private Const CLOCK_REALTIME As Integer = 0

' int clock_gettime (clockid_t __clock_id, struct timespec *__tp)
' Get current value of clock CLOCK_ID and store it in TP.
Private Extern clock_gettime(__clock_id As Integer, __tp As Timespec) As Integer


Public Sub Main()
  
  Dim spec As New Timespec
  
  clock_gettime(CLOCK_REALTIME, spec)
  
  Print spec.tv_sec; ",\e[31m"; spec.tv_nsec; "\e[0m"
  
End


 


...o tambien:
Library "libc:6"

Public Struct timespec
  tv_sec As Long
  tv_nsec As Long
End Struct

Public Struct tm
  tm_sec As Integer
  tm_min As Integer
  tm_hour As Integer
  tm_mday As Integer
  tm_mon As Integer
  tm_year As Integer
  tm_yday As Integer
  tm_isdst As Integer
  tm_gmtoff As Long
  tm_zone As Pointer
End Struct

Private Const CLOCK_REALTIME As Integer = 0

' int clock_gettime (clockid_t __clock_id, struct timespec *__tp)
' Get current value of clock CLOCK_ID and store it in TP.
Private Extern clock_gettime(__clock_id As Integer, __tp As Timespec) As Integer

' size_t strftime (char *__restrict __s, size_t __maxsize, const char *__restrict __format, const struct tm *__restrict __tp)
' Format TP into S according to FORMAT.
Private Extern strftime(__s As Pointer, __maxsize As Long, __format As String, __tp As Tm) As Long

' struct tm *localtime (const time_t *__timer)
' Return the `struct tm' representation of *TIMER in the local timezone.
Private Extern localtime(__timer As Pointer) As Tm


Public Sub Main()

  Dim ts As New Timespec
  Dim buff As New Byte[24]
  Dim tsec As Long

   clock_gettime(CLOCK_REALTIME, ts)
   tsec = ts.tv_sec
  
   strftime(buff.Data, CLong(buff.Count), "%D %T", localtime(VarPtr(tsec)))
  
   Print String@(buff.Data); ".\e[31m"; ts.tv_nsec; "\e[0m"

End

 



 
última edición por vuott el Miercoles, 04 Abril 2018, 16:32; editado 2 veces 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 
OcultarTemas parecidos
Tema Autor Foro Respuestas último mensaje
No hay nuevos mensajes ¿formularios En Tiempo De Ejecución O En... jsoto61 General 1 Jueves, 10 Diciembre 2009, 00:54 Ver último mensaje
fabianfv
No hay nuevos mensajes Problema Para Incluir Un Gridview En Un Fo... jsoto61 Controles/Librerías/Componentes 8 Viernes, 25 Diciembre 2009, 22:14 Ver último mensaje
soplo
No hay nuevos mensajes Telnet (Ejecutar Comandos En Un Servidor U... dquinter General 3 Lunes, 02 Abril 2012, 23:19 Ver último mensaje
jguardon
No hay nuevos mensajes [Python] Utilidades Para Shell Unix Shell Python 0 Jueves, 22 Agosto 2013, 08:19 Ver último mensaje
Shell
 

Publicar nuevo tema  Responder al tema  Página 1 de 2
Ir a la página 1, 2  Siguiente

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario



  

 

cron