Java: change date format - so it'll work
You can easily change the current date format in Java. You can find out exactly how in this practical tip.
Java: How to change the date format
First import with the commands "import java.text.SimpleDateFormat;" and "import java.util.Date;" the required libraries.
- First of all you create with the command "Date today = new Date ();" a new variable that stores the current date.
- Then use "SimpleDateFormat DATE_FORMAT = new SimpleDateFormat (" dd-MM-yyyy ");" the format you want.
- Finally, you can change the date with the command "String date = DATE_FORMAT.format (today);" reformat.
In the next practical tip, we will explain how to use arrays correctly in Java.