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

Da Gambas-it.org - Wikipedia.
(Creata pagina con "Per sapere quanti secondi sono passati dalla data iniziale del tempo "''[https://it.wikipedia.org/wiki/Tempo_(Unix) Unix]''" sino alla data e all'orario correnti, si può adot...")
 
Riga 1: Riga 1:
Per sapere quanti secondi sono passati dalla data iniziale del tempo "''[https://it.wikipedia.org/wiki/Tempo_(Unix) Unix]''" sino alla data e all'orario correnti, si può adottare la seguente semplice modalità:
+
Per sapere quanti secondi sono passati dalla data iniziale del tempo "''[https://it.wikipedia.org/wiki/Tempo_(Unix) Unix]''", anche chiamata ''Epoch'', sino alla data e all'orario correnti, si può adottare la seguente semplice modalità:
 
  '''Public''' Sub Main()
 
  '''Public''' Sub Main()
 
    
 
    
Riga 5: Riga 5:
 
    
 
    
 
  '''End'''
 
  '''End'''
 +
oppure usando le risorse della libreria condivisa "''libglib-2.0.so.0.6400.6'' ":
 +
Library "libglib-2.0:0.6400.6"
 +
 +
 +
<FONT Color=gray>' ''GDateTime * g_date_time_new_now_local (void)''
 +
' ''Creates a GDateTime corresponding to this exact instant in the local time zone.''</font>
 +
Private Extern g_date_time_new_now_local() As Pointer
 +
 +
<FONT Color=gray>' ''gchar * g_date_time_format (GDateTime *datetime, const gchar *format)''
 +
' ''Creates a newly allocated string representing the requested format.''</font>
 +
Private Extern g_date_time_format(datetime As Pointer, _format As String) As String
 +
 +
<FONT Color=gray>' ''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.''</font>
 +
Private Extern g_date_time_unref(datetime As Pointer)
 +
 +
 +
'''Public''' Sub Main()
 +
 
 +
  Dim gdt As Pointer
 +
 
 +
  gdt = g_date_time_new_now_local()
 +
 
 +
<FONT Color=gray>' ''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:''</font>
 +
  Print g_date_time_format(gdt, "%s")
 +
 
 +
  g_date_time_unref(gdt)
 +
 
 +
'''End'''
 +
 +
 +
 +
=Riferimenti=
 +
* https://docs.gtk.org/glib/func.usleep.html?q=g_date

Versione delle 20:11, 22 apr 2023

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à:

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

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

Library "libglib-2.0:0.6400.6"


' 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