Vai al contenuto

Funzioni gestione Data/Ora di sistema

Vai all indice del manuale di programmazione
Tipo: Funzione
Libreria LogicLab: eLLabXUnified12Lib
Libreria Codesys: Non disponibile

Nei sistemi operativi Unix-like il tempo viene rappresentato come offset in secondi rispetto alla mezzanotte (UTC) del 1º gennaio 1970 (detta epoca). Questo tipo di rappresentazione, oltre che a essere compatta, è indipendente dai fusi orari, ed è quindi direttamente confrontabile anche tra systemi situati in posizioni geografiche diverse.

Nota: Le funzioni operano su valori di Data/Ora con un range elevato ma occorre fare riferimento al real time clock presente sul sistema per il valore supportato.

SysDateGetS, get the system date on second

Questa funzione ritorna la data di sistema in UTC espressa in secondi su una variabile a 32 bit. Il range gestito è dalle ore 00:00:00 del 1° Gennaio 1970 alle ore 06:28:15 del 7 Febbraio 2106.

Descrizione

La funzione ritorna una variabile (UDINT) con la data di sistema in UTC.

Immagine F_SysDateGetS

SysDateGetNs, get the system date on ns

Questa funzione ritorna la data di sistema in UTC espressa in ns su una variabile a 64 bit. Il range gestito è dalle ore 00:00:00 del 1° Gennaio 1970 alle ore 23:34:33.709 del 21 Luglio 2554.

Descrizione

La funzione ritorna una variabile (ULINT) con data di sistema in UTC.

Immagine F_SysDateGetNs

SysDateSetS, set the system date on second

Questa funzione imposta la data di sistema in UTC espresso in secondi su una variabile a 32 bit. Il range gestito è dalle ore 00:00:00 del 1° Gennaio 1970 alle ore 06:28:15 del 7 Febbraio 2106.

Sostituisce “SysSetUTCDateTime”

Sostituisce la funzione SysSetUTCDateTime il cui uso è deprecato.

Descrizione

UTCDateTime (UDINT) Valore data di sistema in UTC espressa in secondi.

La funzione ritorna una variabile (BOOL) FALSE: Errore esecuzione, TRUE: Esecuzione Ok.

Immagine F_SysDateSetS

Esempi

Come utilizzare gli esempi.
Nel seguente esempio viene salvato in una variabile il valore ritornato dalla funzione.

LogicLab (Ptp116, ST_DateTimeFunctions)
PROGRAM ST_DateTimeFunctions
VAR
    DTime : DATE_AND_TIME;    (* Date/Time *)
    LDTime : LDATE_AND_TIME;    (* Date/Time *)
    LDTS : ARRAY[0..1] OF LDATETIMESTRUCT;    (* Long Date/Time struct *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_DateTimeFunctions"
// *****************************************************************************
// Use of date functions.
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // 32 BITS DATE FUNCTIONS
    // -------------------------------------------------------------------------
    // The "SysDateGetS" function returns a value in the range
    // From 1970-01-01-00:00:00 to 2106-02-07-06:28:15

    // After conversion in DATE_AND_TIME the range will be
    // From 1970-01-01-00:00:00 to 2038-01-19-03:14:07

    DTime:=TO_DATE_AND_TIME(SysDateGetS());
    eTO_JUNK(SPLIT_DT(TO_DATE_AND_TIME(SysDateGetS()), ADR(LDTS[0].Year), ADR(LDTS[0].Month), ADR(LDTS[0].Day), ADR(LDTS[0].Hours), ADR(LDTS[0].Minutes), ADR(LDTS[0].Seconds)));

    // -------------------------------------------------------------------------
    // 64 BITS DATE FUNCTIONS
    // -------------------------------------------------------------------------
    // The "SysDateGetNs" function returns a value in the range
    // From 1970-01-01-00:00:00 to 2554-07-21-03:23:34:33.709

    // After conversion in LDATE_AND_TIME the range will be
    // From 1970-01-01-00:00:00 to 2262-04-11-23:47:16.854

    LDTime:=TO_LDATE_AND_TIME(SysDateGetNs());
    eTO_JUNK(SPLIT_LDT(TO_LDATE_AND_TIME(SysDateGetNs()), ADR(LDTS[1].Year), ADR(LDTS[1].Month), ADR(LDTS[1].Day), ADR(LDTS[1].Hours), ADR(LDTS[1].Minutes), ADR(LDTS[1].Seconds), ADR(LDTS[1].Milliseconds), ADR(LDTS[1].Microseconds), ADR(LDTS[1].Nanoseconds)));

// [End of file]
Was this article helpful?