Depends on what java version you are using. If java 8 then read javadoc of class DateTimeFormatter and go from there. If any other version read about Joda library or SimpleDateFormat (This one not really recommended) or FastDateFormat of Apache library. This should give you all the info you need
solved How do I produce a timestamp/datetime string of a certain format in Java