Converts millisecond timestamps or Date
objects to time strings.
Time string. string
_D() _D(timestamp) _D(timestamp, fmt)
Millisecond timestamp or Date
object.
timestamp
false
number、object
Format string, JavaScript
language default format: yyyy-MM-dd hh:mm:ss
; Python
language default format: %Y-%m-%d %H:%M:%S
; C++
language default format: %Y-%m-%d %H:%M:%S
.
fmt
false
string
function main(){
var time = _D()
Log(time)
}
def main():
strTime = _D()
Log(strTime)
void main() {
auto strTime = _D();
Log(strTime);
}
Get and print the current time string:
function main() {
Log(_D(1574993606000))
}
def main():
# Running this code on a server in Beijing time: 2019-11-29 10:13:26 , a docker on another server in another region results in: 2019-11-29 02:13:26
Log(_D(1574993606))
void main() {
Log(_D(1574993606000));
}
The timestamp is 1574993606000, using the code conversion:
function main() {
Log(_D(1574993606000, "yyyy--MM--dd hh--mm--ss")) // 2019--11--29 10--13--26
}
def main():
# 1574993606 is timestamped in seconds.
Log(_D(1574993606, "%Y--%m--%d %H--%M--%S")) # 2019--11--29 10--13--26
void main() {
Log(_D(1574993606000, "%Y--%m--%d %H--%M--%S")); // 2019--11--29 10--13--26
}
Formatting with the parameter fmt
is different for JavaScript
, Python
, and C++
languages, as shown in the following examples:
Returns the current time string without passing any parameters. When using the _D()
function in the Python
strategy, you need to be aware that the parameters passed are second-level timestamps (millisecond-level timestamps in the JavaScript and C++ strategies, where 1 second is equal to 1000 milliseconds). When using the _D()
function to parse a time string with a readable timestamp in the live trading, you need to pay attention to the time zone and time setting of the operating system where the docker program is located. The _D()
function parses a timestamp into a readable time string depending on the time of the docker’s system.
{@fun/Global/UnixNano UnixNano}, {@fun/Global/Unix Unix}
_G _N