Sapere quanti secondi sono passati dalla data iniziale del tempo Unix sino alla data e all'orario correnti

Da Gambas-it.org - Wikipedia.

Per sapere quanti secondi sono passati dalla data iniziale del tempo "Unix", anche chiamata Epoch, sino alla data e all'orario correnti, si può adottare la seguente semplice modalità con le sole risorse di Gambas:

Public Sub Main()
 
 Print DateDiff("01/01/1970", Now, gb.Second)
  
End

oppure usando le risorse della libreria condivisa "libglib-2.0.so.0.7200.4 ":

Library "libglib-2.0:0.7200.4" 

' GDateTime * g_date_time_new_now_local (void)
' Creates a GDateTime corresponding to this exact instant in the local time zone.
Private Extern g_date_time_new_now_local() As Pointer

' gchar * g_date_time_format (GDateTime *datetime, const gchar *format)
' Creates a newly allocated string representing the requested format.
Private Extern g_date_time_format(datetime As Pointer, _format As String) As String

' void g_date_time_unref (GDateTime *datetime)
' Atomically decrements the reference count of datetime by one.
' When the reference count reaches zero, the resources allocated by datetime are freed.
Private Extern g_date_time_unref(datetime As Pointer)


Public Sub Main()
 
 Dim gdt As Pointer
 
 gdt = g_date_time_new_now_local()
 
' Al 2° parametro va impostato il formato "%s" che rappresenta il numero di secondi dall'Epoca, cioè dal 1970-01-01 00:00:00 UTC:
 Print g_date_time_format(gdt, "%s")
 
 g_date_time_unref(gdt)
  
End


Riferimenti