Time Functions

Finding out the current model time

You can get current model (logical) time using the function time(). There are two notations: the simple one, time() returns the current model time as number of model time units simulated since the model start. Another, time(TIME_UNIT) returns the number of specified time units simulated so far. For example, time(MINUTE) returns the number of simulated minutes (a double value).

Finding out the current date, day of week, hour of day, etc.

The date in AnyLogic is stored in the form of the Java class Date. Date is composed of the year, month, day of month, hour of the day, minute, second and millisecond. To find out the current date, you should call the function date().

A number of functions return particular components of the current date (and all those functions also have the form without a parameter, in which case they return the component of a given, not current, date):

Functions to make model independent of time unit settings

Let’s say the time unit in your model is hours. What if you need to schedule something to happen in 2 days? Or how would you define a duration of 5 minutes? Of course, you could write 48 and 5.0/60. But a much better solution is to use the special functions that return the value of a given time interval with respect to the current time unit settings:

For example, if the time unit is hours, minute() will return 0.0166, and week() will return 168.0. Thus, instead of remembering what the current time unit is and writing 48 or 5./60, you can simply write 2*day() and 5*minute(). You can also combine different units in one expression: 3 * hour() + 20 * minute().

What is probably even more important about these functions is that the expressions using them are completely independent of the time unit settings: the expressions always evaluate to the correct time intervals. Therefore, we recommend always using multipliers such as minute(), hour(), day(), etc. in the numeric expressions that represent time intervals: this way, you can freely change the time units without changing the model.

Conversion functions