Spanish [SOLUCIONADO] Problema al hacer operaciones con horas

Discussion in 'Spanish Forum' started by Edu Portu, Jul 2, 2019.

  1. Edu Portu

    Edu Portu Member Licensed 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

    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
  2. emexes

    emexes Well-Known Member 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.
    José J. Aguilar likes this.
  3. emexes

    emexes Well-Known Member Licensed User

    This is a dodgy shortcut to formatting time:
    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:
    If T_Jornada > 3600000 Then
    Log(NumberFormat2(T_Jornada / 3600000111False) & " hours")
    Else If T_Jornada > 60000 Then
    Log(NumberFormat2(T_Jornada / 60000111False) & " minutes")
    Log(NumberFormat2(T_Jornada / 1000111False) & " seconds")
    End If
  4. emexes

    emexes Well-Known Member Licensed User

    Dim Seconds As Int = T_Jornada / 1000
    Dim Minutes As Int = Seconds / 60
    Seconds = Seconds - Minutes * 
    Dim Hours As Int = Minutes / 60
    Minutes = Minutes - Hours * 

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

    emexes Well-Known Member Licensed User

    inakigarm likes this.
  6. Edu Portu

    Edu Portu Member Licensed User

    Lo he solucinado poniendo DateTime.SetTimeZone(0)

    Muchas gracias
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice