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

    Code:
    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
     
  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:
    Code:
    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:
    Code:
    If T_Jornada > 3600000 Then
        
    Log(NumberFormat2(T_Jornada / 3600000111False) & " hours")
    Else If T_Jornada > 60000 Then
        
    Log(NumberFormat2(T_Jornada / 60000111False) & " minutes")
    Else
        
    Log(NumberFormat2(T_Jornada / 1000111False) & " seconds")
    End If
     
  4. emexes

    emexes Well-Known Member Licensed User

    Or:
    Code:
    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, 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
     
Loading...
  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