Differenze tra le versioni di "Sapere quanti secondi bisogna aggiungere all'orario locale per ottenere l'orario UTC"

Da Gambas-it.org - Wikipedia.
Riga 1: Riga 1:
 
Per sapere in Italia ([https://it.wikipedia.org/wiki/Central_European_Time Central European Time]) quanti secondi bisogna aggiungere all'orario locale per ottenere l'orario [https://it.wikipedia.org/wiki/Tempo_coordinato_universale UTC], si può utilizzare la Proprietà ".TimeZone" della Classe ''System'':
 
Per sapere in Italia ([https://it.wikipedia.org/wiki/Central_European_Time Central European Time]) quanti secondi bisogna aggiungere all'orario locale per ottenere l'orario [https://it.wikipedia.org/wiki/Tempo_coordinato_universale UTC], si può utilizzare la Proprietà ".TimeZone" della Classe ''System'':
  '''Public''' Sub Main()
+
  Public Sub Main()
 
    
 
    
 
   Print System.TimeZone
 
   Print System.TimeZone
 
    
 
    
  '''End'''
+
End
 +
 
 +
 
 +
==Uso delle risorse esterne di GLib-2.0==
 +
Library "libglib-2.0:0.7200.4"
 +
 +
Private Enum G_TIME_TYPE_STANDARD = 0, G_TIME_TYPE_DAYLIGHT, G_TIME_TYPE_UNIVERSAL
 +
 +
<FONT Color=gray>' ''GTimeZone ° g_time_zone_new_identifier(const gchar °identifier)''
 +
  ' ''Creates a GTimeZone corresponding to identifier.''</font>
 +
Private Extern g_time_zone_new_identifier(identifier As String) As Pointer
 +
 +
<FONT Color=gray>' ''gint g_time_zone_find_interval(GTimeZone *tz, GTimeType type, gint64 time_)''
 +
' ''Find an interval within tz that corresponds to given time_.''</font>
 +
Private Extern g_time_zone_find_interval(tz As Pointer, type As Integer, time_ As Long) As Integer
 +
 +
<FONT Color=gray>' ''gint32 g_time_zone_get_offset(GTimeZone *tz, gint interval)''
 +
' ''Determines the offset to UTC.''</font>
 +
Private Extern g_time_zone_get_offset(tz As Pointer, interval As Integer) As Integer
 +
 +
<FONT Color=gray>' ''void g_time_zone_unref(GTimeZone *tz)''
 +
' ''Decreases the reference count on tz.''</font>
 +
Private Extern g_time_zone_unref(tz As Pointer)
 +
 +
 +
Public Sub Main()
 +
 +
  Dim gtz As Pointer
 +
  Dim itv, off As Integer
 +
  Dim timezone As String
 +
 +
  timezone = Replace(File.Load("/etc/timezone"), gb.NewLine, "\x00")
 +
 +
  gtz = g_time_zone_new_identifier(timezone)
 +
  If gtz == 0 Then Error.Raise("Errore !")
 +
 +
  itv = g_time_zone_find_interval(gtz, G_TIME_TYPE_STANDARD, DateDiff(CDate("01/01/1970 00:00:00"), Now, gb.Second))
 +
 +
  off = g_time_zone_get_offset(gtz, itv)
 +
  Print off; " = "; Time(0, 0, 0, off * 1000)
 +
 +
  g_time_zone_unref(gtz)
 +
 +
End

Versione delle 12:37, 18 giu 2023

Per sapere in Italia (Central European Time) quanti secondi bisogna aggiungere all'orario locale per ottenere l'orario UTC, si può utilizzare la Proprietà ".TimeZone" della Classe System:

Public Sub Main()
 
 Print System.TimeZone
 
End


Uso delle risorse esterne di GLib-2.0

Library "libglib-2.0:0.7200.4"

Private Enum G_TIME_TYPE_STANDARD = 0, G_TIME_TYPE_DAYLIGHT, G_TIME_TYPE_UNIVERSAL

' GTimeZone ° g_time_zone_new_identifier(const gchar °identifier)
' Creates a GTimeZone corresponding to identifier.
Private Extern g_time_zone_new_identifier(identifier As String) As Pointer

' gint g_time_zone_find_interval(GTimeZone *tz, GTimeType type, gint64 time_)
' Find an interval within tz that corresponds to given time_.
Private Extern g_time_zone_find_interval(tz As Pointer, type As Integer, time_ As Long) As Integer

' gint32 g_time_zone_get_offset(GTimeZone *tz, gint interval)
' Determines the offset to UTC.
Private Extern g_time_zone_get_offset(tz As Pointer, interval As Integer) As Integer

' void g_time_zone_unref(GTimeZone *tz)
' Decreases the reference count on tz.
Private Extern g_time_zone_unref(tz As Pointer)


Public Sub Main()

 Dim gtz As Pointer
 Dim itv, off As Integer
 Dim timezone As String

 timezone = Replace(File.Load("/etc/timezone"), gb.NewLine, "\x00")

 gtz = g_time_zone_new_identifier(timezone)
 If gtz == 0 Then Error.Raise("Errore !")

 itv = g_time_zone_find_interval(gtz, G_TIME_TYPE_STANDARD, DateDiff(CDate("01/01/1970 00:00:00"), Now, gb.Second))

 off = g_time_zone_get_offset(gtz, itv)
 Print off; " = "; Time(0, 0, 0, off * 1000)

 g_time_zone_unref(gtz)

End