Differenze tra le versioni di "Ottenere con le risorse della libreria standard C "time.h" la data nella forma "giorno-della-settimana mese giorno ora:min:sec anno""

Da Gambas-it.org - Wikipedia.
 
Riga 16: Riga 16:
 
  '''Public''' Sub Main()
 
  '''Public''' Sub Main()
 
    
 
    
  Dim l As Long
+
  Dim l As Long
  Dim s As String
+
  Dim s As String
 
    
 
    
 
   l = time_C(0)
 
   l = time_C(0)

Versione attuale delle 16:22, 16 gen 2022

Con le funzioni esterne time( ) e ctime( ), contenute nella libreria standard C "/usr/include/time.h", è possibile ottenere la data corrente nella forma stringa "giorno-della-settimana mese giorno ora:minuti:secondi anno".


Mostriamo un semplice esempio pratico:

Library "libc:6"

' time_t time (time_t *__timer)
' Return the current time and put it in *TIMER if TIMER is not NULL.
Private Extern time_C(__timer As Pointer) As Long Exec "time"

' char *ctime (const time_t *__timer)
' Equivalent to `asctime (localtime (timer))'.
Private Extern ctime(__timer As Pointer) As String


Public Sub Main()
 
  Dim l As Long
  Dim s As String
 
  l = time_C(0)
   
  s = ctime(VarPtr(l))
  Print s
  
End