Type/to search
Built-in Functions
Global
Version
IsVirtual
GetOS
GetPid
GetMeta
Sleep
Unix
UnixNano
_D
GetCommand
GetLastError
SetErrorFilter
_N
_C
_Cross
JSON.parse
JSON.stringify
Encode
MD5
UUID
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Convert a millisecond-level timestamp or a Date object into a time string.

_D()
_D(timestamp)
_D(timestamp, fmt)

Examples

  • Get and print the current time string.

    javascript
    function main(){ var time = _D() Log(time) }
    python
    def main(): strTime = _D() Log(strTime)
    rust
    fn main() { let time = _D(None); Log!(time); }
  • The timestamp is 1574993606000; convert it with code.

    javascript
    function main() { Log(_D(1574993606000)) }
    python
    def main(): # Running on a server set to Beijing time, the result is: 2019-11-29 10:13:26; while running # this code on a docker on a server in another region gives the result: 2019-11-29 02:13:26 Log(_D(1574993606))
    rust
    fn main() { Log!(_D(1574993606000)); }
  • Format using the fmt argument. The format strings for JavaScript and Python differ; please refer to the following examples for details.

    javascript
    function main() { Log(_D(1574993606000, "yyyy--MM--dd hh--mm--ss")) // Output: 2019--11--29 10--13--26 }
    python
    def main(): # 1574993606 is a second-level timestamp Log(_D(1574993606, "%Y--%m--%d %H--%M--%S")) # Output: 2019--11--29 10--13--26
    rust
    fn main() { // Rust's _D() function does not support the fmt argument; it only supports the default format: // yyyy-MM-dd hh:mm:ss Log!(_D(1574993606000)); // Output: 2019-11-29 02:13:26 (UTC) }

Returns

TypeDescription

string

The time string.

Arguments

NameTypeRequiredDescription

timestamp

number / object

No

A millisecond-level timestamp or a Date object.

fmt

string

No

The format string. Default format for JavaScript: yyyy-MM-dd hh:mm:ss; default format for Python: %Y-%m-%d %H:%M:%S.

See Also

Remarks

If no argument is passed, the current time string is returned. When using the _D() function in a Python strategy, note that the argument passed in is a second-level timestamp (in JavaScript and Rust strategies it is a millisecond-level timestamp; 1 second equals 1000 milliseconds). When using the _D() function in live trading to parse a timestamp into a readable time string, note the time zone and time settings of the operating system on which the docker (hosting program) runs, because the parsing result of the _D() function depends on the docker system's time. The _D() function in Rust is not affected by the docker system's time zone and always outputs UTC time.