Home > database >  AnyLogic Date format
AnyLogic Date format

Time:02-06

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

CodePudding user response:

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("d", getDayOfMonth()) "."
 String.format("d",getMonth() 1) "."
 String.format("d",getYear()) " "
 String.format("d",getHourOfDay()) ":"
 String.format("d",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);
  • Related