Modelica打印当前时间

Modelica print current time

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

https://build.openmodelica.org/Documentation/Modelica.Utilities.Streams.print.html

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

.Modelica.Utilities.Streams.print(String(time));

本地系统时间使用: https://build.openmodelica.org/Documentation/Modelica.Utilities.System.getTime.html

model GetTime
  Integer ms;
  Integer sec;
  Integer min;
  Integer hour;
  Integer mday;
  Integer mon;
  Integer year;
algorithm
  (ms, sec, min, hour, mday, mon, year) := .Modelica.Utilities.System.getTime();
  .Modelica.Utilities.Streams.print("ms:" + String(ms) + "\n");
  .Modelica.Utilities.Streams.print("sec:" + String(sec) + "\n");
  .Modelica.Utilities.Streams.print("min:" + String(min) + "\n");
  .Modelica.Utilities.Streams.print("hour:" + String(hour) + "\n");
  .Modelica.Utilities.Streams.print("mday:" + String(mday) + "\n");
  .Modelica.Utilities.Streams.print("mon:" + String(mon) + "\n");
  .Modelica.Utilities.Streams.print("year:" + String(year) + "\n");
end GetTime;

自 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"

Durations是Testing库中的另一条算子记录,可以处理时间跨度。