Spanish [SOLUCIONADO] Problema al hacer operaciones con horas

Edu Portu

Member
Licensed User
Longtime User
Buenos dias,
Tengo un problema al hacer operaciones con horas, ya que al restar 2 horas (entrada y salida) me añade una hora automaticamente.

Un ejemplo, tengo una hora de entrada y otra de salida en formato LONG, al restarlas me da 7 segundos (T_jornada=7622), pero al hacer el

B4X:
DateTime.Time(T_jornada)

me devuelve 01:00:07

porque puede ser? He hecho bastantes pruebas y siempre le añade 1 hora. Adjunto foto del ejemplo

Saludos y muchas gracias
Edu
 

emexes

Expert
Licensed User
The 01:00:00 "error" will be due to your timezone and/or daylight savings.

Time 0 is midnight 12:00:00am on 01/01/1970 UTC ie London. At that same instant, in your current location, the local time was one hour later.

So I am guessing you are about one hour (15 degrees) east of London.
 

emexes

Expert
Licensed User
This is a dodgy shortcut to formatting time:
B4X:
Dim TimeZero As Long = DateTime.TimeParse("00:00:00")
Log(DateTime.Time(TimeZero + 7600))
I'm looking for a better one. Or you could always just work it out yourself, eg:
B4X:
If T_Jornada > 3600000 Then
    Log(NumberFormat2(T_Jornada / 3600000, 1, 1, 1, False) & " hours")
Else If T_Jornada > 60000 Then
    Log(NumberFormat2(T_Jornada / 60000, 1, 1, 1, False) & " minutes")
Else
    Log(NumberFormat2(T_Jornada / 1000, 1, 1, 1, False) & " seconds")
End If
 

emexes

Expert
Licensed User
Or:
B4X:
Dim Seconds As Int = T_Jornada / 1000
Dim Minutes As Int = Seconds / 60
Seconds = Seconds - Minutes * 60
Dim Hours As Int = Minutes / 60
Minutes = Minutes - Hours * 60

Dim T As String = NumberFormat2(Hours, 2, 0, 0, False) & ":" & NumberFormat2(Minutes, 2, 0, 0, False) & ":" & NumberFormat2(Seconds, 2, 0, 0, False)
Should be ok, assuming integer division without rounding.
 
Top