How do I obtain current simulation date and time?

How do I obtain current simulation date and time?

aditya_prakash1
Not applicable
82 Views
7 Replies
Message 1 of 8

How do I obtain current simulation date and time?

aditya_prakash1
Not applicable

[ FlexSim 16.1.0 ]

How do I obtain current date. Is realtime() the best way to do it?

Accepted solutions (1)
83 Views
7 Replies
Replies (7)
Message 2 of 8

Ben_WilsonADSK
Community Manager
Community Manager

realtime() will give you the real current date and time, from your computer's clock. This should closely match the time you see on your watch, your cell phone, or the clock on the wall. This is different than the time in your simulation.

If you are looking for the current date in your simulation, this is based on your chosen time unit and start date, both specified when starting a new model.

921-modelunits.png

As you're running your simulation, you can obtain various date and time values for current simulation time from the tree as shown here:

922-simtime.gif

Message 3 of 8

matt_long
Not applicable
Accepted solution

There's a new command in FlexSim 2106 called convert(). Convert allows you to convert dates and times from different formats like Excel Date Time, FlexSim Date Time and Model Time. This is especially useful when importing data from Excel that is based upon specific dates and times.

A couple of ways you can use the convert() command is in conjunction with the time() command and getmodelunit()

getmodelunit(CURRENT_TIME) //Returns FS_DATETIME
time() //Returns model time
convert(time(), MODEL_TIME, DATETIME_STR) //Will print out date time based upon the date/time format string, for example 8:00:00 AM Fri 24 Jun 2016

Check out the command documentation for convert() for more information.

Message 4 of 8

michael_h5
Not applicable

Matt - where can I find the command documentation?

0 Likes
Message 5 of 8

joshua_s
Not applicable

@Michael Under the Help Tab click on "FlexScript API Reference" or the "Commands"

14187-pic1.png

Message 6 of 8

preetdesai
Not applicable

Hi @Ben Wilson ! How would I convert realtime(); to DD/MM/YYYY HH:MM:SS timeformat?

0 Likes
Message 7 of 8

jason_lightfootVL7B4
Autodesk
Autodesk

Here's a script to print your string to the output console:

string year=realtime(12).substr(21,4);            //  2023
string datestr=realtime(11);                      //  11/13/23
string date=datestr.substr(1,6)+year;             //  11/13/2023
string realtimeString=date+" "+realtime(10);      //  11/13/2023 23:23:10
DateTime dt=DateTime(realtimeString,"%m/%d/%Y %T");
print (dt.toString("%d/%m/%Y %T"));            // 13/11/2023 23:23:10
0 Likes
Message 8 of 8

preetdesai
Not applicable
Thank you @Jason Lightfoot . That worked fine!
0 Likes