Questa funzione da eseguire in task Back, restituisce una stringa formattata in base alla stringa di formato indicata in pFormat utilizzando il valore di Data/Ora indicato in LDTValue.
La stringa formattata è accodata al contenuto del buffer indicato da pRString la cui dimensione deve essere passata in RSLength.
Per inizializzare la stringa di ritorno si può inserire il carattere “^” come primo carattere della definizione di formattazione. In caso di errore esecuzione la funzione ritorna FALSE.
Sostituisce il FB “DateTimeFormat”
Per eseguire la formattazione della data/ora si utilizzava il FB DateTimeFormat, ora sostituito da una funzione con lo stesso nome. Se non si vuole modificare il programma nella libreria eLLabObsoleteLib si trova il FB FBDateTimeFormat copia del precedente FB.
Descrizione
LDTValue (LDATE_AND_TIME) Valore data in Unix Epoch time (1 gennaio 1970).
pFormat (@STRING) Puntatore a definizione formattazione.
pRString (@STRING) Puntatore a buffer stringa risultato formattata.
RSLength (UDINT) Dimensione buffer stringa risultato formattata.
La funzione ritorna un (BOOL) FALSE se errore esecuzione, TRUE se esecuzione corretta.

Definizione caratteri formattazione
Format | Description | |
---|---|---|
Space | Returned on output | |
d | Day of the month, 2 digits with leading zeros | 01~31 |
m | Numeric representation of a month, with leading zeros | 01~12 |
Y | A full numeric representation of a year, 4 digits | Examples: 1999 or 2003 |
y | A two digit representation of a year | Examples: 99 or 03 |
H | 24-hour format of an hour with leading zeros | 00~23 |
i | Minutes with leading zeros | 00~59 |
s | Seconds with leading zeros | 00~59 |
u | Microsecond | 000~999 |
v | Millisecond | 000~999 |
U | Seconds since the Unix Epoch | Example 1663863622 |
\ | Escape the following character | Example \H |
^ | Initialize the return string (To be used at beginning of definition) |
Esempi
Come utilizzare gli esempi.
Nell’esempio è riportata la formattazione della Data/Ora di sistema in diversi formati.
LogicLab (Ptp201, ST_DateTimeFormat)
PROGRAM ST_DateTimeFormat
VAR
RSts : ARRAY[0..6] OF BOOL; (* Result status *)
LDTValue : LDATE_AND_TIME; (* Long Date/Time value *)
Result1 : STRING[ 32 ]; (* Result string *)
Result2 : STRING[ 32 ]; (* Result string *)
Result3 : STRING[ 32 ]; (* Result string *)
Result4 : STRING[ 32 ]; (* Result string *)
Result5 : STRING[ 32 ]; (* Result string *)
Result6 : STRING[ 32 ]; (* Result string *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_DateTimeFormat"
// *****************************************************************************
// The system Date/Time is formatted in some various strings.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// DATE/TIME FORMATTING
// -------------------------------------------------------------------------
// Date/Time formatting examples.
LDTValue:=TO_LDATE_AND_TIME(SysDateGetNs()); //Long Date/Time value
RSts[0]:=DateTimeFormat(LDTValue, ADR('^\E\p\o\c\h U'), ADR(Result1), SIZEOF(Result1)); //Epoch 1663863622
RSts[1]:=DateTimeFormat(LDTValue, ADR('^"Time" H\:i\:s'), ADR(Result2), SIZEOF(Result2)); //Time 16:20:33
RSts[2]:=DateTimeFormat(LDTValue, ADR('^"Long time" H\:i\:s\.vu'), ADR(Result3), SIZEOF(Result3)); //Long time 16:20:41.122918
RSts[3]:=DateTimeFormat(LDTValue, ADR('^"Date" d\/m\/Y'), ADR(Result4), SIZEOF(Result4)); //Date 22/09/2022
RSts[4]:=DateTimeFormat(LDTValue, ADR('^"Date/Time" d/m/Y\ H\:i\:s'), ADR(Result5), SIZEOF(Result5)); //Date/Time 22/09/2022 16:21:08
// Here an example how to concatenate formatted results.
RSts[5]:=DateTimeFormat(LDTValue, ADR('^"Date" d/m/Y'), ADR(Result6), SIZEOF(Result6));
RSts[6]:=DateTimeFormat(LDTValue, ADR('", Time" H\:i\:s'), ADR(Result6), SIZEOF(Result6)); //Date 22/09/2022, Time 16:21:08
// [End of file]