Differenze tra le versioni di "Sapere quanti nanosecondi sono passati dalla data iniziale del tempo Unix sino alla data e all'orario correnti"

Da Gambas-it.org - Wikipedia.
 
Riga 14: Riga 14:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
    
 
    
 
   Dim spec As New Timespec
 
   Dim spec As New Timespec
Riga 22: Riga 22:
 
   Print "\e[31m"; (spec.tv_sec * 1000000000) + spec.tv_nsec; "\e[0m"
 
   Print "\e[31m"; (spec.tv_sec * 1000000000) + spec.tv_nsec; "\e[0m"
 
    
 
    
  '''End'''
+
  End

Versione attuale delle 08:21, 1 lug 2024

Per sapere quanti nanosecondi sono passati dalla data iniziale del tempo "Unix" sino alla data e all'orario correnti, è possibile utilizzare la funzione esterna "clock_gettime()" della libreria standard C e definita nel file header "/usr/include/time.h ".

Library "libc:6"

Public Struct timespec
  tv_sec As Long
  tv_nsec As Long
End Struct

Private Const CLOCK_REALTIME As Integer = 0

' int clock_gettime (clockid_t __clock_id, struct timespec *__tp)
' Get current value of clock CLOCK_ID and store it in TP.
Private Extern clock_gettime(__clock_id As Integer, __tp As Timespec) As Integer


Public Sub Main()
 
  Dim spec As New Timespec
 
  clock_gettime(CLOCK_REALTIME, spec)
  
  Print "\e[31m"; (spec.tv_sec * 1000000000) + spec.tv_nsec; "\e[0m"
  
End