Java gets the current time of the system and formats createtime--2018 May 9 11:41:00author:marydon
There are two ways of implementing
ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;/*** Get System Current time * @descrition using calendar implementation *@paramformat *@return */ Publicstring Getsysdatestr (string format) {Date sysdate=calendar.getinstance (). GetTime (); Format= "". Equals (format)? " Yyyy-mm-dd HH:mm:ss ": Format; SimpleDateFormat SDF=NewSimpleDateFormat (format); returnSdf.format (sysdate);}/*** Get System Current time * @descrition using date implementation *@paramformat *@return */ Publicstring getSysdateStr2 (string format) {Date sysdate=NewDate (); Format= "". Equals (format)? " Yyyy-mm-dd HH:mm:ss ": Format; SimpleDateFormat SDF=NewSimpleDateFormat (format); returnSdf.format (sysdate);}
Related recommendations:
- Java Date Tool class Dateutils
Java gets the current time of the system and formats it