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

Da Gambas-it.org - Wikipedia.
 
(4 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
Per sapere 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à:
+
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] <SUP>&#091;[[#Note|nota 1]]&#093;</sup>, si può utilizzare la Proprietà ".TimeZone" della Classe ''System'':
* " ''.TimeZone'' " della Classe ''System'':
+
  Public Sub Main()
  '''Public''' Sub Main()
 
 
    
 
    
 
   Print System.TimeZone
 
   Print System.TimeZone
 
    
 
    
  '''End'''
+
  End
  
* oppure eseguire il seguente calcolo:
+
 
  '''Public''' Sub Main()
+
==Uso delle risorse esterne di GLib-2.0==
    
+
Library "libglib-2.0:0.7800.4"
   Print Round(Frac(Date(Now)) * 24) * -3600
+
    
+
Private Enum G_TIME_TYPE_STANDARD = 0, G_TIME_TYPE_DAYLIGHT, G_TIME_TYPE_UNIVERSAL
  '''End'''
+
 +
<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
 +
 
 +
 
 +
 
 +
=Note=
 +
[1] Tempo universale coordinato (UTC): La base del tempo civile dal 1960. È approssimativamente uguale all'ora solare media al meridiano primo (0 gradi di longitudine).

Versione attuale delle 15:23, 26 apr 2024

Per sapere in Italia (Central European Time) quanti secondi bisogna aggiungere all'orario locale per ottenere l'orario UTC [nota 1], 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.7800.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


Note

[1] Tempo universale coordinato (UTC): La base del tempo civile dal 1960. È approssimativamente uguale all'ora solare media al meridiano primo (0 gradi di longitudine).