When writing a policy, you will inevitably encounter problems with the use of timestamps, which in JS are a number on the millisecond scale. It is usually not very intuitive and is mainly used in the program to judge the order of time before time, calculate time difference, etc. It is not very convenient during DEBUG or debugging. For this, the platform has a built-in function: _D() function, which is used to display the timestamp as a string for ease of use. Also sometimes it is necessary to convert a specific time description into a timestamp, so how do you do that?
Here's an example of code:
function main(){
// example TimeString to TimeStamp
//timeStr format: "2016.12.01 13:55:60";
var stamp = new Date("2014-07-10 10:21:12:500").getTime();
Log("stamp:", stamp,"_D(stamp)" ,_D(stamp) ,"srting : 2014-07-10 10:21:12");
//timeStr format: "2016.12.01 13:55:60:300";
var stamp2 = new Date("2014-07-10 10:21:12").getTime();
Log("stamp2:", stamp2,"_D(stamp)" ,_D(stamp2) ,"srting : 2014-07-10 10:21:12");
var nowTimeStamp = new Date().getTime();
var nowTimeStr = _D(nowTimeStamp);
Log(new Date(nowTimeStr).getTime(), nowTimeStamp);
}
Code retesting is running:
Note that the _D() function is used a little differently in Python, and we'll test it in code as well.
import time
def main():
# example TimeString to TimeStamp
# timeStr format: "2016.12.01 13:55:60";
# time.mktime(tupletime)
# 接受时间元组并返回时间辍(1970纪元后经过的浮点秒数)。
stamp = time.mktime((2014, 7, 10, 10, 21, 12, 5, 0, 0))
Log("stamp:", stamp, "_D(stamp)", _D(stamp)," srting : 2014-07-10 10:21:12")
stamp2 = time.mktime((2014, 7, 10, 10, 21, 12, 0, 0, 0))
Log("stamp2:", stamp2, "_D(stamp)", _D(stamp2), "srting : 2014-07-10 10:21:12")
nowTimeStamp = time.time()
nowTimeStr = _D(nowTimeStamp)
Log("nowTimeStamp:", nowTimeStamp, "nowTimeStr:", nowTimeStr)
The results showed:
super888_D() The unit of time in the python platform is seconds, which is different from the one in the description.
Inventors quantify - small dreamsOh yeah, thanks for the reminder, I've added explanations for python ^^, but in python's policy, you can use the _D input parameter to directly return a value with Python time.time (). The time stamps in the K-line data are of the millisecond scale, and need to be converted to 1000 in the Python policy to be used for the secondary time stamps returned by the comparison time.time ().