能否在TDL(Tally定义语言)中传入毫秒级时间?及mm-dd-yyy hh:mm:ss格式日期时间转毫秒是否可行?
Great questions about working with precise timestamps in TDL! Let’s break down each one clearly:
1. Can we pass time in milliseconds in TDL?
TDL doesn’t natively support a datetime data type that includes milliseconds—most of Tally’s built-in datetime operations operate at the second level. But that’s not a dead end! A practical workaround is to split your precise timestamp into two components:
- Store the core datetime (without milliseconds) in a standard TDL datetime field.
- Store the milliseconds as a separate integer field.
When you need to use the full precise timestamp (for calculations or external integrations), you can combine these two values in your custom TDL logic.
2. Converting mm-dd-yyyy hh:mm:ss datetime to milliseconds in TDL?
There’s no out-of-the-box TDL function to directly convert a datetime string to a Unix timestamp (milliseconds since epoch), but you can build a custom solution using existing TDL tools:
- Step 1: Parse the input string into a valid TDL datetime object using the
$Datefunction. You’ll need to specify the input format to ensure Tally interprets it correctly:$Date:"mm-dd-yyyy hh:mm:ss" "your-input-datetime-string" - Step 2: Calculate the difference from the Unix epoch (January 1, 1970 00:00:00) using the
$DateDifffunction, which returns the difference in seconds. - Step 3: Convert to milliseconds by multiplying the second count by 1000.
Important note: Tally’s datetime handling depends on the system’s local timezone. If your use case requires UTC-based milliseconds, you’ll need to add timezone adjustment logic to account for that.
内容的提问来源于stack exchange,提问作者Rohini

