Datetime Modelica打印当前时间

Datetime Modelica打印当前时间,datetime,modelica,Datetime,Modelica,如何从Modelica将当前日期和/或时间打印到文件(如日志文件或csv文件)?我需要外部代码吗?我在Modelica标准库中找不到任何示例代码。 您需要将其添加到方程或算法部分: .Modelica.Utilities.Streams.print(String(time)); 对于本地系统时间使用: 从v1.1开始,测试库(Dymola 2019附带)包含操作员记录DateTime 操作员记录有几个构造函数。如果没有给出进一步的参数,则使用系统时间。以下是一个例子: > dt =Te

如何从Modelica将当前日期和/或时间打印到文件(如日志文件或csv文件)?我需要外部代码吗?我在Modelica标准库中找不到任何示例代码。

您需要将其添加到方程或算法部分:

.Modelica.Utilities.Streams.print(String(time));
对于本地系统时间使用:


从v1.1开始,测试库(Dymola 2019附带)包含操作员记录
DateTime

操作员记录有几个构造函数。如果没有给出进一步的参数,则使用系统时间。以下是一个例子:

> dt =Testing.Utilities.Time.DateTime()   // use getTime() to create the operator record
> dt.a                                    // access one of the variables of the operator record
= 2019
> String(dt)                              // convert to string using default format
= "2019-10-14 12:31:50"
> String(dt, format="%Hh %MINmin %Ss")    // convert to string using custom format
= "12h 35min 12s"

持续时间
是测试库中的另一个操作员记录,可以处理时间跨度。

我使用的工具(Dymola)返回正确的时间,但年份除外。我今年得到的整数是10。这是预期的吗?getTime的C代码在这里定义:我打开了一个MSL错误:我也回答了。今天是2019-10-10,上面的“月”实际上是一个月中的一天。您将得到…小时、月、日、年作为结果。我的错,对此表示抱歉,我现在更正了对getTime()的调用。如何从.mos脚本加载测试库?我需要使用Dymola安装目录中子文件夹的完整路径吗?使用命令
DymolaCommands.SimulatorAPI.openModelFile(“测试”)
> dt =Testing.Utilities.Time.DateTime()   // use getTime() to create the operator record
> dt.a                                    // access one of the variables of the operator record
= 2019
> String(dt)                              // convert to string using default format
= "2019-10-14 12:31:50"
> String(dt, format="%Hh %MINmin %Ss")    // convert to string using custom format
= "12h 35min 12s"