Various methods and formats for obtaining the current time of the system in Java_DracoTianlong’s Blog

/** * Returns the current datetime string * Default format: yyyy-mm-dd hh:mm:ss * * @return String returns the current string type date time */ public static String getCurrentTime() { String returnStr = null; SimpleDateFormat f = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); Date date = new Date(); returnStr = f. format(date); return returnStr; } /** * Returns the current datetime string * Default format: yyyymmddhhmmss * * @return String returns the current string type date time */ public static BigDecimal getCurrentTimeAsNumber() { String returnStr = null; SimpleDateFormat f = new SimpleDateFormat(“yyyyMMddHHmmss”); Date date = new Date(); returnStr = f. format(date); return new BigDecimal(returnStr); } /** * Returns the current datetime string in a custom format * * @param format * format rules * @return String returns the current string type date time */ public static String getCurrentTime(String format) { String returnStr = null; SimpleDateFormat f = new SimpleDateFormat(format); Date date = new Date(); returnStr = f. format(date); return returnStr; } /** * Return the current string date * * @return String Returned string date */ public static String getCurDate() { Calendar calendar = Calendar. getInstance(); SimpleDateFormat simpledateformat = new SimpleDateFormat(“yyyy-MM-dd”); String strDate = simpledateformat. format(calendar. getTime()); return strDate; } /** * Returns a…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索