Edu Portu Member Licensed User Longtime User Jul 2, 2019 #1 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
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
E emexes Expert Licensed User Jul 2, 2019 #2 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.
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.
E emexes Expert Licensed User Jul 2, 2019 #3 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
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
E emexes Expert Licensed User Jul 2, 2019 #4 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.
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.
E emexes Expert Licensed User Jul 2, 2019 #5 On the shoulders of giants https://www.b4x.com/android/forum/threads/b4x-dateutils-simplifies-date-and-time-calcuations.26290/ and in particular: B4X: 'Calculates the period between two date instances. 'This method returns a Period type with years, months, days, hours, minutes, seconds. Sub PeriodBetween(Start As Long, EndTime As Long) As Period
On the shoulders of giants https://www.b4x.com/android/forum/threads/b4x-dateutils-simplifies-date-and-time-calcuations.26290/ and in particular: B4X: 'Calculates the period between two date instances. 'This method returns a Period type with years, months, days, hours, minutes, seconds. Sub PeriodBetween(Start As Long, EndTime As Long) As Period
Edu Portu Member Licensed User Longtime User Jul 17, 2019 #6 Lo he solucinado poniendo DateTime.SetTimeZone(0) Muchas gracias