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

convert time to hour and minutes

convert time to hour and minutes

Hi everybody I am quiet new from OpenModelica and I have several issue.
I am trying to convert the time for obtaining the corresponding in hour and minutes, but I don't how to write in the code for count until 59 minutes and when reach 60 add an hour and restart minutes from 00. This is the code:

model fromTimetoHour
  Real min;
  Real hour;
equation
  min = div(time, 60);
  hour = div(time, 3600);
end fromTimetoHour

If i set in the simulation the end time at 31536000 (second in one year) and with this code I obtain the total hours and minutes of the whole year.
But my aim is trying to have the classic visualization in  hh:mm

someone can help me?

Edited by: Aigor88 - Sep-03-15 09:28:57

Re: convert time to hour and minutes

Real second = mod(time, 60);
Real minute = mod(div(time, 60), 60);
Real hour = mod(div(time, 3600), 24);
Real days = div(time, 3600*24);

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