Differenze tra le versioni di "Sapere quanti secondi sono passati dall'inizio dell'anno corrente"

Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Per sapere quanti secondi sono trascorsi dall'inizio del corrente anno, è possibile utilizzare alcune funzioni esterne della libreria ''time.h'' di C, come segue: Public Str...')
 
Riga 1: Riga 1:
 
Per sapere quanti secondi sono trascorsi dall'inizio del corrente anno, è possibile utilizzare alcune funzioni esterne della libreria ''time.h'' di C, come segue:
 
Per sapere quanti secondi sono trascorsi dall'inizio del corrente anno, è possibile utilizzare alcune funzioni esterne della libreria ''time.h'' di C, come segue:
 
  Public Struct tm
 
  Public Struct tm
   tm_sec As Integer      ' secondi (0 - 59)
+
   tm_sec As Integer      <FONT Color=gray>' ''secondi (0 - 59)''</font>
   tm_min As Integer      ' minuti (0 - 59)
+
   tm_min As Integer      <FONT Color=gray>' ''minuti (0 - 59)''</font>
   tm_hour As Integer    ' ore (0 - 23)
+
   tm_hour As Integer    <FONT Color=gray>' ''ore (0 - 23)''</font>
   tm_mday As Integer    ' Giorno del mese (1 - 31)
+
   tm_mday As Integer    <FONT Color=gray>' ''Giorno del mese (1 - 31)''</font>
   tm_mon As Integer      ' Mese (1 - 12)
+
   tm_mon As Integer      <FONT Color=gray>' ''Mese (1 - 12)''</font>
   tm_year As Integer    ' Anno (numero di anni dal 1900)
+
   tm_year As Integer    <FONT Color=gray>' ''Anno (numero di anni dal 1900)''</font>
   tm_wday As Integer    ' Giorno della Settimana (0 - 6)
+
   tm_wday As Integer    <FONT Color=gray>' ''Giorno della Settimana (0 - 6)''</font>
   tm_yday As Integer    ' Giorno nell'Anno (0 - 365)
+
   tm_yday As Integer    <FONT Color=gray>' ''Giorno nell'Anno (0 - 365)''</font>
   tm_isdst As Integer    ' ora legale
+
   tm_isdst As Integer    <FONT Color=gray>' ''ora legale''</font>
 
  End Struct
 
  End Struct
 
   
 
   
 
  Library "libc:6"
 
  Library "libc:6"
 +
 +
<FONT Color=gray>' ''time_t time (time_t* timer)''
 +
' ''Get the current calendar time as a value of type time_t.''
 +
' ''The value returned generally represents the number of seconds since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp).''</font>
 +
Private Extern Time_C(timerptr As Pointer) As Long Exec "time"
 +
 +
<FONT Color=gray>' ''tm* localtime( const time_t *time )''
 +
' ''Converts given time since epoch as time_t value into calendar time, expressed in local time.''</font>
 +
Private Extern localtime(tm As Pointer) As Pointer
 
   
 
   
 
  <FONT Color=gray>' ''double difftime (time_t end, time_t beginning)''
 
  <FONT Color=gray>' ''double difftime (time_t end, time_t beginning)''
Riga 21: Riga 30:
 
  ' ''Converts the structure pointed to by timeptr into a time_t value according to the local time zone.''</font>
 
  ' ''Converts the structure pointed to by timeptr into a time_t value according to the local time zone.''</font>
 
  Private Extern mktime(timerptr As Tm) As Long
 
  Private Extern mktime(timerptr As Tm) As Long
 
<FONT Color=gray>' ''time_t time (time_t* timer)''
 
' ''Get the current calendar time as a value of type time_t.''
 
' ''The value returned generally represents the number of seconds since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp).''</font>
 
Private Extern Time_C(timerptr As Pointer) As Long Exec "time"
 
 
<FONT Color=gray>' ''tm* localtime( const time_t *time )''
 
' ''Converts given time since epoch as time_t value into calendar time, expressed in local time.''</font>
 
Private Extern localtime(tm As Pointer) As Pointer
 
 
 
   
 
   
 +
 
 
  '''Public''' Sub Main()
 
  '''Public''' Sub Main()
 
   
 
   
Riga 51: Riga 51:
 
   
 
   
 
   sec = difftime(t, mktime(tempus))
 
   sec = difftime(t, mktime(tempus))
 
+
 
   Print "Secondi trascorsi sino ad oggi dall'inizio dell'anno corrente:  "; sec
 
   Print "Secondi trascorsi sino ad oggi dall'inizio dell'anno corrente:  "; sec
 
   
 
   
 
  '''End'''
 
  '''End'''

Versione delle 18:30, 7 nov 2014

Per sapere quanti secondi sono trascorsi dall'inizio del corrente anno, è possibile utilizzare alcune funzioni esterne della libreria time.h di C, come segue:

Public Struct tm
  tm_sec As Integer      ' secondi (0 - 59)
  tm_min As Integer      ' minuti (0 - 59)
  tm_hour As Integer     ' ore (0 - 23)
  tm_mday As Integer     ' Giorno del mese (1 - 31)
  tm_mon As Integer      ' Mese (1 - 12)
  tm_year As Integer     ' Anno (numero di anni dal 1900)
  tm_wday As Integer     ' Giorno della Settimana (0 - 6)
  tm_yday As Integer     ' Giorno nell'Anno (0 - 365)
  tm_isdst As Integer    ' ora legale
End Struct

Library "libc:6"

' time_t time (time_t* timer)
' Get the current calendar time as a value of type time_t.
' The value returned generally represents the number of seconds since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp).
Private Extern Time_C(timerptr As Pointer) As Long Exec "time"

' tm* localtime( const time_t *time )
' Converts given time since epoch as time_t value into calendar time, expressed in local time.
Private Extern localtime(tm As Pointer) As Pointer

' double difftime (time_t end, time_t beginning)
' Returns the number of seconds elapsed between time time1 and time time0, represented as a double.
Private Extern difftime(endl As Long, beginningl As Long) As Float

' time_t mktime(struct tm *timeptr)
' Converts the structure pointed to by timeptr into a time_t value according to the local time zone.
Private Extern mktime(timerptr As Tm) As Long

 
Public Sub Main()

 Dim tempus As New Tm
 Dim t As Long
 Dim sec As Float
 
  Time_C(VarPtr(t))

  tempus = localtime(VarPtr(t))

  With tempus
    .tm_mon = 0
    .tm_mday = 1
    .tm_hour = 0
    .tm_min = 0
    .tm_sec = 0
  End With

  sec = difftime(t, mktime(tempus))

  Print "Secondi trascorsi sino ad oggi dall'inizio dell'anno corrente:  "; sec

End