Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Use day, hours minutes and second from PC

Use day, hours minutes and second from PC

I tried to see in the Forum but I don't find anything.

I would like to use the day hours minutes and second from PC settings. Is it possible? How can I manage this problem?

Thanks to all

Re: Use day, hours minutes and second from PC

external c function?

Re: Use day, hours minutes and second from PC

i don't understand
what do you mean?

Re: Use day, hours minutes and second from PC

If I got you right, you want to get the current time within your Modelica model. That can be done easily using external functions. The following is a brief example that extracts the current hours information:

Code:


model TimeTest
  impure function getHours
    output Integer x;
  external "C" x = _getHours() annotation(Include = "#include <stdio.h>
    #include <time.h>
    int _getHours()
    {
      time_t now;
      struct tm *ts;
     
      /* Get the current time */
      now = time(NULL);
      ts = localtime(&now);
     
      return ts->tm_hour;
    }");
  end getHours;

  parameter Integer h = getHours();
end TimeTest;

Re: Use day, hours minutes and second from PC

yes exactly! it works!
but how can i add also minutes and the date ?
thanks for the help

Re: Use day, hours minutes and second from PC

All these information is available from the struct tm:
year: tm->tm_year+1900
month: tm->tm_mon
day: tm->tm_mday
hour tm->tm_hour
minute: tm->tm_min
second: tm->tm_sec

There are 0 guests and 0 other users also viewing this topic
You are here: