Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
Time Formatting

A comprehensive set of functions for converting timestamps to formatted strings. More...

Topics

 Time structure formatting
 
void time_shield::process_format_impl (char last_char, size_t repeat_count, ts_t ts, tz_t utc_offset, const DateTimeStruct &dt, std::string &result)
 
template<class T = ts_t>
const std::string time_shield::to_string (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Convert timestamp to string with custom format.
 
template<class T = ts_t>
const std::string time_shield::to_str (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Alias for to_string function.
 
template<class T = ts_ms_t>
const std::string time_shield::to_string_ms (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Convert timestamp in milliseconds to string with custom format.
 
template<class T = ts_t>
const std::string time_shield::to_str_ms (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Alias for to_string function.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601 (T ts)
 Converts a timestamp to an ISO8601 string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_date (T ts)
 Converts a timestamp to an ISO8601 date string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_time (T ts)
 Converts a timestamp to an ISO8601 time string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_time_utc (T ts)
 Converts a timestamp to an ISO8601 UTC time string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_utc (T ts)
 Converts a timestamp to an ISO8601 string in UTC format.
 
const std::string time_shield::to_iso8601_utc_ms (ts_ms_t ts_ms)
 Converts a timestamp in milliseconds to an ISO8601 string in UTC format.
 
const std::string time_shield::to_iso8601_ms (ts_ms_t ts_ms)
 Converts a timestamp in milliseconds to an ISO8601 string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601 (T ts, tz_t utc_offset)
 Converts a timestamp to an ISO8601 string with timezone offset.
 
const std::string time_shield::to_iso8601_ms (ts_ms_t ts_ms, tz_t utc_offset)
 Converts a timestamp in milliseconds to an ISO8601 string with timezone offset.
 
const std::string time_shield::to_mql5_date_time (ts_t ts)
 Converts a timestamp to a string in MQL5 date and time format.
 
const std::string time_shield::to_mql5_full (ts_t ts)
 Alias for to_mql5_date_time_str function.
 
const std::string time_shield::to_mql5_date (ts_t ts)
 Converts a timestamp to a string in MQL5 date format.
 
const std::string time_shield::to_mql5_time (ts_t ts)
 Converts a timestamp to a string in MQL5 time format.
 
const std::string time_shield::to_windows_filename (ts_t ts)
 Converts a timestamp in seconds to a Windows-compatible filename format.
 
const std::string time_shield::to_windows_filename_ms (ts_ms_t ts)
 Converts a timestamp in milliseconds to a Windows-compatible filename format.
 
std::string time_shield::to_human_readable (ts_t ts)
 Converts a timestamp in seconds to a human-readable format.
 
std::string time_shield::to_human_readable_ms (ts_ms_t ts)
 Converts a timestamp in milliseconds to a human-readable format.
 
string time_shield::pad_int (int value, int width)
 Internal helper to pad integer with leading zeros.
 
void time_shield::process_format_impl (const char last_char, int repeat_count, long ts, int utc_offset, const DateTimeStruct &dt, string &result)
 Internal helper for custom formatting processing.
 
string time_shield::to_string (string format_str, long timestamp, int utc_offset=0)
 Convert timestamp to string with custom format.
 
string time_shield::to_str (string format_str, long timestamp, int utc_offset=0)
 Alias for to_string.
 
string time_shield::to_string_ms (string format_str, long timestamp_ms, int utc_offset=0)
 Convert millisecond timestamp to string with custom format.
 
string time_shield::to_str_ms (string format_str, long timestamp_ms, int utc_offset=0)
 Alias for to_string_ms.
 
string time_shield::to_iso8601 (long ts)
 Convert timestamp to ISO8601 string.
 
string time_shield::to_iso8601_ms (long ts_ms)
 Convert millisecond timestamp to ISO8601 string.
 
string time_shield::to_iso8601_date (long ts)
 Convert timestamp to ISO8601 date string.
 
string time_shield::to_iso8601_time (long ts)
 Convert timestamp to ISO8601 time string.
 
string time_shield::to_iso8601_time_ms (long ts_ms)
 Convert millisecond timestamp to ISO8601 time string.
 
string time_shield::to_iso8601_utc (long ts)
 Convert timestamp to ISO8601 string in UTC.
 
string time_shield::to_iso8601_utc_ms (long ts_ms)
 Convert millisecond timestamp to ISO8601 string in UTC.
 
string time_shield::to_iso8601 (long ts, int utc_offset)
 Convert timestamp to ISO8601 string with timezone offset.
 
string time_shield::to_iso8601_ms (long ts_ms, int utc_offset)
 Convert millisecond timestamp to ISO8601 string with timezone offset.
 
string time_shield::to_mql5_date_time (long ts)
 Convert timestamp to MQL5 date-time string.
 
string time_shield::to_mql5_date (long ts)
 Convert timestamp to MQL5 date string.
 
string time_shield::to_mql5_time (long ts)
 Convert timestamp to MQL5 time string.
 
string time_shield::to_mql5_full (long ts)
 Alias for to_mql5_date_time.
 
string time_shield::to_windows_filename (long ts)
 Convert timestamp to Windows-compatible filename.
 
string time_shield::to_windows_filename_ms (long ts_ms)
 Convert millisecond timestamp to Windows-compatible filename.
 
string time_shield::to_human_readable (long ts)
 Convert timestamp to human-readable string.
 
string time_shield::to_human_readable_ms (long ts_ms)
 Convert millisecond timestamp to human-readable string.
 

Detailed Description

A comprehensive set of functions for converting timestamps to formatted strings.

This module provides utilities for formatting timestamps into human-readable strings, custom formats, ISO8601, and other standardized formats.

Key Features:

Usage Examples:

Function Documentation

◆ pad_int()

string time_shield::pad_int ( int value,
int width )

Internal helper to pad integer with leading zeros.

Parameters
valueInteger value to pad.
widthDesired width of the number.
Returns
String with left-padded digits.

Definition at line 37 of file time_formatting.mqh.

◆ process_format_impl() [1/2]

void time_shield::process_format_impl ( char last_char,
size_t repeat_count,
ts_t ts,
tz_t utc_offset,
const DateTimeStruct & dt,
std::string & result )
inline

Definition at line 21 of file time_formatting.hpp.

◆ process_format_impl() [2/2]

void time_shield::process_format_impl ( const char last_char,
int repeat_count,
long ts,
int utc_offset,
const DateTimeStruct & dt,
string & result )

Internal helper for custom formatting processing.

This function handles individual format specifiers used by to_string and to_string_ms.

Parameters
last_charCurrent format character.
repeat_countNumber of repeats of the format character.
tsTimestamp in seconds.
utc_offsetUTC offset in seconds.
dtDateTimeStruct corresponding to the timestamp.
resultOutput string being built.

Definition at line 59 of file time_formatting.mqh.

◆ to_human_readable() [1/2]

string time_shield::to_human_readable ( long ts)

Convert timestamp to human-readable string.

Parameters
tsTimestamp in seconds.
Returns
String in format "YYYY-MM-DD HH:MM:SS".

Definition at line 469 of file time_formatting.mqh.

◆ to_human_readable() [2/2]

std::string time_shield::to_human_readable ( ts_t ts)

Converts a timestamp in seconds to a human-readable format.

Parameters
tsThe timestamp in seconds.
Returns
A string in the format "YYYY-MM-DD HH:MM:SS".

Definition at line 750 of file time_formatting.hpp.

◆ to_human_readable_ms() [1/2]

string time_shield::to_human_readable_ms ( long ts_ms)

Convert millisecond timestamp to human-readable string.

Parameters
ts_msTimestamp in milliseconds.
Returns
String in format "YYYY-MM-DD HH:MM:SS.SSS".

Definition at line 477 of file time_formatting.mqh.

◆ to_human_readable_ms() [2/2]

std::string time_shield::to_human_readable_ms ( ts_ms_t ts)

Converts a timestamp in milliseconds to a human-readable format.

Parameters
tsThe timestamp in milliseconds.
Returns
A string in the format "YYYY-MM-DD HH:MM:SS.SSS".

Definition at line 760 of file time_formatting.hpp.

◆ to_iso8601() [1/4]

string time_shield::to_iso8601 ( long ts)

Convert timestamp to ISO8601 string.

Parameters
tsTimestamp in seconds.
Returns
ISO8601 formatted string (YYYY-MM-DDTHH:MM:SS).

Definition at line 347 of file time_formatting.mqh.

◆ to_iso8601() [2/4]

string time_shield::to_iso8601 ( long ts,
int utc_offset )

Convert timestamp to ISO8601 string with timezone offset.

Parameters
tsTimestamp in seconds.
utc_offsetOffset from UTC in seconds.
Returns
ISO8601 string with timezone offset.

Definition at line 402 of file time_formatting.mqh.

◆ to_iso8601() [3/4]

template<class T = ts_t>
const std::string time_shield::to_iso8601 ( T ts)
inline

Converts a timestamp to an ISO8601 string.

This function converts a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in ISO8601 format.

Definition at line 525 of file time_formatting.hpp.

◆ to_iso8601() [4/4]

template<class T = ts_t>
const std::string time_shield::to_iso8601 ( T ts,
tz_t utc_offset )
inline

Converts a timestamp to an ISO8601 string with timezone offset.

This function converts a timestamp to a string in ISO8601 format with timezone offset.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
utc_offsetThe timezone offset in seconds.
Returns
A string representing the timestamp in ISO8601 format with timezone offset.

Definition at line 643 of file time_formatting.hpp.

◆ to_iso8601_date() [1/2]

string time_shield::to_iso8601_date ( long ts)

Convert timestamp to ISO8601 date string.

Parameters
tsTimestamp in seconds.
Returns
Date in ISO8601 format (YYYY-MM-DD).

Definition at line 363 of file time_formatting.mqh.

◆ to_iso8601_date() [2/2]

template<class T = ts_t>
const std::string time_shield::to_iso8601_date ( T ts)
inline

Converts a timestamp to an ISO8601 date string.

This function converts the date part of a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the date part of the timestamp in ISO8601 format.

Definition at line 544 of file time_formatting.hpp.

◆ to_iso8601_ms() [1/4]

string time_shield::to_iso8601_ms ( long ts_ms)

Convert millisecond timestamp to ISO8601 string.

Parameters
ts_msTimestamp in milliseconds.
Returns
ISO8601 formatted string with milliseconds.

Definition at line 355 of file time_formatting.mqh.

◆ to_iso8601_ms() [2/4]

string time_shield::to_iso8601_ms ( long ts_ms,
int utc_offset )

Convert millisecond timestamp to ISO8601 string with timezone offset.

Parameters
ts_msTimestamp in milliseconds.
utc_offsetOffset from UTC in seconds.
Returns
ISO8601 string with milliseconds and timezone offset.

Definition at line 412 of file time_formatting.mqh.

◆ to_iso8601_ms() [3/4]

const std::string time_shield::to_iso8601_ms ( ts_ms_t ts_ms)
inline

Converts a timestamp in milliseconds to an ISO8601 string.

This function converts a timestamp in milliseconds to a string in ISO8601 format.

Parameters
ts_msThe timestamp in milliseconds to convert.
Returns
A string representing the timestamp in ISO8601 format with milliseconds.

Definition at line 627 of file time_formatting.hpp.

◆ to_iso8601_ms() [4/4]

const std::string time_shield::to_iso8601_ms ( ts_ms_t ts_ms,
tz_t utc_offset )
inline

Converts a timestamp in milliseconds to an ISO8601 string with timezone offset.

This function converts a timestamp in milliseconds to a string in ISO8601 format with timezone offset.

Parameters
ts_msThe timestamp in milliseconds to convert.
utc_offsetThe timezone offset in seconds.
Returns
A string representing the timestamp in ISO8601 format with timezone offset and milliseconds.

Definition at line 670 of file time_formatting.hpp.

◆ to_iso8601_time() [1/2]

string time_shield::to_iso8601_time ( long ts)

Convert timestamp to ISO8601 time string.

Parameters
tsTimestamp in seconds.
Returns
Time in ISO8601 format (HH:MM:SS).

Definition at line 371 of file time_formatting.mqh.

◆ to_iso8601_time() [2/2]

template<class T = ts_t>
const std::string time_shield::to_iso8601_time ( T ts)
inline

Converts a timestamp to an ISO8601 time string.

This function converts the time part of a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in ISO8601 format.

Definition at line 559 of file time_formatting.hpp.

◆ to_iso8601_time_ms()

string time_shield::to_iso8601_time_ms ( long ts_ms)

Convert millisecond timestamp to ISO8601 time string.

Parameters
ts_msTimestamp in milliseconds.
Returns
Time in ISO8601 format with milliseconds.

Definition at line 379 of file time_formatting.mqh.

◆ to_iso8601_time_utc()

template<class T = ts_t>
const std::string time_shield::to_iso8601_time_utc ( T ts)
inline

Converts a timestamp to an ISO8601 UTC time string.

This function converts the time part of a timestamp to a string in ISO8601 format with 'Z' indicating UTC.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in ISO8601 format with 'Z' indicating UTC.

Definition at line 578 of file time_formatting.hpp.

◆ to_iso8601_utc() [1/2]

string time_shield::to_iso8601_utc ( long ts)

Convert timestamp to ISO8601 string in UTC.

Parameters
tsTimestamp in seconds.
Returns
ISO8601 string with trailing 'Z'.

Definition at line 387 of file time_formatting.mqh.

◆ to_iso8601_utc() [2/2]

template<class T = ts_t>
const std::string time_shield::to_iso8601_utc ( T ts)
inline

Converts a timestamp to an ISO8601 string in UTC format.

This function converts a timestamp to a string in ISO8601 format with UTC timezone.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in ISO8601 UTC format.

Definition at line 597 of file time_formatting.hpp.

◆ to_iso8601_utc_ms() [1/2]

string time_shield::to_iso8601_utc_ms ( long ts_ms)

Convert millisecond timestamp to ISO8601 string in UTC.

Parameters
ts_msTimestamp in milliseconds.
Returns
ISO8601 string with milliseconds and trailing 'Z'.

Definition at line 394 of file time_formatting.mqh.

◆ to_iso8601_utc_ms() [2/2]

const std::string time_shield::to_iso8601_utc_ms ( ts_ms_t ts_ms)
inline

Converts a timestamp in milliseconds to an ISO8601 string in UTC format.

This function converts a timestamp in milliseconds to a string in ISO8601 format with UTC timezone.

Parameters
ts_msThe timestamp in milliseconds to convert.
Returns
A string representing the timestamp in ISO8601 UTC format with milliseconds.

Definition at line 614 of file time_formatting.hpp.

◆ to_mql5_date() [1/2]

string time_shield::to_mql5_date ( long ts)

Convert timestamp to MQL5 date string.

Parameters
tsTimestamp in seconds.
Returns
String in format "YYYY.MM.DD".

Definition at line 433 of file time_formatting.mqh.

◆ to_mql5_date() [2/2]

const std::string time_shield::to_mql5_date ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 date format.

This function converts a timestamp to a string in MQL5 date format (yyyy.mm.dd).

Parameters
tsThe timestamp to convert.
Returns
A string representing the date part of the timestamp in MQL5 format.

Definition at line 707 of file time_formatting.hpp.

◆ to_mql5_date_time() [1/2]

string time_shield::to_mql5_date_time ( long ts)

Convert timestamp to MQL5 date-time string.

Parameters
tsTimestamp in seconds.
Returns
String in format "YYYY.MM.DD HH:MM:SS".

Definition at line 425 of file time_formatting.mqh.

◆ to_mql5_date_time() [2/2]

const std::string time_shield::to_mql5_date_time ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 date and time format.

This function converts a timestamp to a string in MQL5 date and time format (yyyy.mm.dd hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in MQL5 date and time format.

Definition at line 688 of file time_formatting.hpp.

◆ to_mql5_full() [1/2]

string time_shield::to_mql5_full ( long ts)

Alias for to_mql5_date_time.

Converts a timestamp to a string in MQL5 date and time format.

This function converts a timestamp to a string in MQL5 date and time format (yyyy.mm.dd hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in MQL5 date and time format.

Definition at line 448 of file time_formatting.mqh.

◆ to_mql5_full() [2/2]

const std::string time_shield::to_mql5_full ( ts_t ts)
inline

Alias for to_mql5_date_time_str function.

Converts a timestamp to a string in MQL5 date and time format.

This function converts a timestamp to a string in MQL5 date and time format (yyyy.mm.dd hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in MQL5 date and time format.

Definition at line 697 of file time_formatting.hpp.

◆ to_mql5_time() [1/2]

string time_shield::to_mql5_time ( long ts)

Convert timestamp to MQL5 time string.

Parameters
tsTimestamp in seconds.
Returns
String in format "HH:MM:SS".

Definition at line 441 of file time_formatting.mqh.

◆ to_mql5_time() [2/2]

const std::string time_shield::to_mql5_time ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 time format.

This function converts a timestamp to a string in MQL5 time format (hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in MQL5 format.

Definition at line 720 of file time_formatting.hpp.

◆ to_str() [1/2]

template<class T = ts_t>
const std::string time_shield::to_str ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )
inline

Alias for to_string function.

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 427 of file time_formatting.hpp.

◆ to_str() [2/2]

string time_shield::to_str ( string format_str,
long timestamp,
int utc_offset = 0 )

Alias for to_string.

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 281 of file time_formatting.mqh.

◆ to_str_ms() [1/2]

template<class T = ts_t>
const std::string time_shield::to_str_ms ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )
inline

Alias for to_string function.

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 510 of file time_formatting.hpp.

◆ to_str_ms() [2/2]

string time_shield::to_str_ms ( string format_str,
long timestamp_ms,
int utc_offset = 0 )

Alias for to_string_ms.

Definition at line 336 of file time_formatting.mqh.

◆ to_string() [1/2]

template<class T = ts_t>
const std::string time_shield::to_string ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 378 of file time_formatting.hpp.

◆ to_string() [2/2]

string time_shield::to_string ( string format_str,
long timestamp,
int utc_offset = 0 )

Convert timestamp to string with custom format.

This function works similarly to the C++ strftime implementation and supports most of its specifiers along with several custom ones.

Parameters
format_strFormat string with specifiers, e.g. "%H:%M:%S".
timestampTimestamp in seconds.
utc_offsetUTC offset in seconds (default 0).
Returns
Formatted string according to format_str.

Definition at line 238 of file time_formatting.mqh.

◆ to_string_ms() [1/2]

template<class T = ts_ms_t>
const std::string time_shield::to_string_ms ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )

Convert timestamp in milliseconds to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp in milliseconds.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 461 of file time_formatting.hpp.

◆ to_string_ms() [2/2]

string time_shield::to_string_ms ( string format_str,
long timestamp_ms,
int utc_offset = 0 )

Convert millisecond timestamp to string with custom format.

Works the same as to_string but accepts a timestamp in milliseconds.

Parameters
format_strFormat string with specifiers.
timestamp_msTimestamp in milliseconds.
utc_offsetUTC offset in seconds (default 0).
Returns
Formatted string according to format_str.

Definition at line 293 of file time_formatting.mqh.

◆ to_windows_filename() [1/2]

string time_shield::to_windows_filename ( long ts)

Convert timestamp to Windows-compatible filename.

Parameters
tsTimestamp in seconds.
Returns
String in format "YYYY-MM-DD_HH-MM-SS".

Definition at line 453 of file time_formatting.mqh.

◆ to_windows_filename() [2/2]

const std::string time_shield::to_windows_filename ( ts_t ts)
inline

Converts a timestamp in seconds to a Windows-compatible filename format.

Parameters
tsThe timestamp in seconds.
Returns
A string in the format "YYYY-MM-DD_HH-MM-SS".

Definition at line 730 of file time_formatting.hpp.

◆ to_windows_filename_ms() [1/2]

string time_shield::to_windows_filename_ms ( long ts_ms)

Convert millisecond timestamp to Windows-compatible filename.

Parameters
ts_msTimestamp in milliseconds.
Returns
String in format "YYYY-MM-DD_HH-MM-SS-SSS".

Definition at line 461 of file time_formatting.mqh.

◆ to_windows_filename_ms() [2/2]

const std::string time_shield::to_windows_filename_ms ( ts_ms_t ts)
inline

Converts a timestamp in milliseconds to a Windows-compatible filename format.

Parameters
tsThe timestamp in milliseconds.
Returns
A string in the format "YYYY-MM-DD_HH-MM-SS-SSS".

Definition at line 740 of file time_formatting.hpp.