Search code examples
dateanylogic

AnyLogic Date format


Is there a way to change the date format in AnyLogic, without constructing something with the implemented Time functions?

I want my Date to be displayed in such a way "E dd.MM.yyyy HH:mm"

With the timefunctions I have problems, to get the date into the right format


Solution

  • Not sure what that E stands for, but if it's the timezone, you can get it with this:

    ZoneId.of("Europe/Oslo").getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH)
    

    I used Europe/Oslo there, but you can find the zone ids that you need here: https://docs.oracle.com/middleware/12211/wcs/tag-ref/MISC/TimeZones.html

    to use this you need to import libraries in Main/Advanced Java/Imports section

    import java.time.ZoneId;
    import java.time.format.TextStyle;
    

    And then to get the required code with that format:

    "E "+String.format("%02d", getDayOfMonth())+"."
    +String.format("%02d",getMonth()+1)+"."
    +String.format("%04d",getYear())+" "
    +String.format("%02d",getHourOfDay())+":"
    +String.format("%02d",getMinute())
    

    You can replace the "E " with what I explained before

    Or you can use whatever is currently your timezone... AnyLogic uses your computer timezone in order to know what timezone you are in:

    Calendar cal=Calendar.getInstance();
    cal.setTime(date());
    String timezoneCode=cal.getTimeZone().toZoneId().getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH);