📅  最后修改于: 2022-03-11 14:57:34.629000             🧑  作者: Mango
private fun setDateFormat() {
val c = Calendar.getInstance()
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.time)
val sdfDate = SimpleDateFormat("yyyy-MMM-dd").format(c.time)
//(yyyy-MMM-dd -> 2022-Jan-14), (yyyy-MM-dd -> 2022-01-14), (yyyy-MMMM-dd -> 2022-January-14)
val sdfTime24 = SimpleDateFormat("HH:mm:ss aa").format(c.time)
val sdfTimeAm = SimpleDateFormat("hh:mm aa").format(c.time)
Log.d("Date",
"\n sdf : $sdf" +
"\n sdfDate : $sdfDate" +
"\n sdfTime24 : $sdfTime24" +
"\n sdfTimeAm : $sdfTimeAm")
/*
* Outut
* sdf : 2022-01-14 21:09:54
* sdfDate : 2022-Jan-14
* sdfTime24 : 21:09:54 pm
* sdfTimeAm : 09:09 pm
*/
}