第1个回答 推荐于2021-02-24
/**
* 获取当前时间, 格式为: yyyy-mm-dd hh-mm-ss
* @return String 当前时间
*/
public static String getNow()
{
return DateFormat.getDateTimeInstance(2, 2, getLocale()).format( new java.util.Date() );
}
/**
* 获取当前时间, 格式为: yyyy年mm月dd日 上午/下午hh时mm分ss秒
* @return String 当前时间
*/
public static String getNowLong()
{
return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, getLocale()).format( new java.util.Date() );
}
/**
* 获取当前时间(精确到毫秒), 格式为: yyyy-mm-dd hh:mm:ss.nnn
* @return String 当前时间
*/
public static String getNowNano()
{
return new java.sql.Timestamp( System.currentTimeMillis() ).toString();
}
/**
* 获取指定的Locale对象
* @return Locale 返回Locale对象
*/
private static Locale getLocale()
{
return Locale.CHINESE;
}本回答被提问者采纳