_D
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:
javascriptfunction main(){ var time = _D() Log(time) }pythondef main(): strTime = _D() Log(strTime)rustfn main() { let time = _D(None); Log!(time); }c++void main() { auto strTime = _D(); Log(strTime); } -
The timestamp is 1574993606000; convert it with code:
javascriptfunction main() { Log(_D(1574993606000)) }pythondef 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))rustfn main() { Log!(_D(1574993606000)); }c++void main() { Log(_D(1574993606000)); } -
Format using the
fmtargument. The format strings forJavaScript,Python, andC++differ; please refer to the following examples for details:javascriptfunction main() { Log(_D(1574993606000, "yyyy--MM--dd hh--mm--ss")) // 2019--11--29 10--13--26 }pythondef main(): # 1574993606 is a second-level timestamp Log(_D(1574993606, "%Y--%m--%d %H--%M--%S")) # 2019--11--29 10--13--26rustfn 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)); // 2019-11-29 10:13:26 }c++void main() { Log(_D(1574993606000, "%Y--%m--%d %H--%M--%S")); // 2019--11--29 10--13--26 }
Returns
| Type | Description |
string | The time string. |
Arguments
| Name | Type | Required | Description |
timestamp | number / object | No | A millisecond-level timestamp or a |
fmt | string | No | The format string. Default format for |
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 C++ 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.