Conoscere il giorno della settimana di una data mediante le risorse della libreria standard C "time.h"

Da Gambas-it.org - Wikipedia.

Per sapere a quale giorno della settimana corrisponde una determinata data, è possibile utilizzare alcune risorse dichiarate nel file header "/usr/include/time.h" della libreria standard di C.


Mostriamo un esempio pratico:

Library "libc:6"

Public Struct tm
  tm_sec As Integer
  tm_min As Integer
  tm_hour As Integer
  tm_mday As Integer
  tm_mon As Integer
  tm_year As Integer
  tm_wday As Integer
  tm_yday As Integer
  tm_isdst As Integer
  tm_gmtoff As Long
  tm_zone As Pointer
End Struct
 
' time_t mktime (struct tm *__tp)
' Return the `time_t' representation of TP and normalize TP.
Private Extern mktime(__tp As Tm) As Long


Public Sub Main()
 
 Dim anno, mese, giorno As Integer
 Dim info As New Tm
 Dim giornosettimana As String[] = ["domenica", "lunedì", "martedì", "mercoledì", "giovedì",
                                   "venerdì", "sabato"]
 
' Imposta la data:
  anno = 1969
  mese = 8
  giorno = 21
  
  With info
    .tm_year = anno - 1900
    .tm_mon = mese - 1
    .tm_mday = giorno
  End With
  
  mktime(info)
  
  Print "Il giorno è un: "; giornosettimana[info.tm_wday]
  
End