question

Gabriel D16 avatar image
0 Likes"
Gabriel D16 asked Gabriel D16 commented

how to set the model's clock to the computer's ?

Hello, I would like to be able to set the time of my simulation with the exact time of the PC when I launch the simulation. (with the code in Model Triggers, onRunStart)


For the moment I use this code but I don't know how to configure with the PC time :

DateTime startTime = DateTime("05/11/2022 10:27:42 AM", "%m/%d/%Y %I:%M:%S %p"); 
function_s(getmodelunit(START_TIME_NODE), "setDateTime", startTime);


Thank you for the help !

model clock time
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jason Lightfoot avatar image
2 Likes"
Jason Lightfoot answered Gabriel D16 commented

There's a post for that here. You can find the computer time with:

realtime(11)+" "+realtime(10)      // returns 05/13/22 18:04:49

or

realtime(12)       //returns   Fri May 13 18:05:54 2022


· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

And to convert it into a DateTime:

DateTime startTime = DateTime(realtime(11) + " " + realtime(10), "%m/%d/%y %H:%M:%S");
2 Likes 2 ·
Gabriel D16 avatar image Gabriel D16 Matthew Gillespie ♦♦ ·
thank you very much, it works well !
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.