Warm tip: This article is reproduced from stackoverflow.com, please click
anylogic

Get system time and convert to string

发布于 2020-05-25 16:42:19

I am trying to get the System date and time and use that in the setFile() method to prevent overwriting my output files. Any idea how I can do that? I went down the path of Calendar.YEAR, etc. but that will give me model date and time not System. Any suggestions on how to proceed.

Questioner
M Rawat
Viewed
46
Benjamin 2020-03-10 15:26

You can easily create a String of your current system time using:

Date currentDate = new Date(System.currentTimeMillis());
String dateAsString = currentDate.toString();

Use that in your setFile() method for the filename and you will never overwrite any outputs (unless you ran them in the same exact second :-) ).