Formatting a calendar date

前端 未结 5 664
不思量自难忘°
不思量自难忘° 2021-02-02 07:06

I just want the date to show up like so:

Saturday, May 26, 2012 at 10:42 PM

Here\'s my code so far:

Calendar calendar = Calendar.get         


        
5条回答
  •  萌比男神i
    2021-02-02 07:33

    For me this works perfectly:

    val cal = Calendar.getInstance()
    
    val pattern = "EEEE, MMMM d, yyyy 'at' h:mm a"
    val primaryLocale = getLocales(resources.configuration).get(0)
    val dateFormat = SimpleDateFormat(dateFormatPattern, primaryLocale)
    
    val formatedDate: String = dateFormat.format(cal.time)
    
    

提交回复
热议问题