本文介紹了如何將日期格式化為字符串,例如“2000 年 12 月 31 日"在爪哇的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試使用 SimpleDateFormat
類來執行此操作,但我沒有找到任何在一天之后放置 'st' 的選項.我只能得到 '31 Dec, 2000'
I tried to use the SimpleDateFormat
class to do this, But I did not find any options that put a 'st' after the day. I could only get '31 Dec, 2000'
如何格式化 "31st Dec, 2000" .我有以毫秒為單位的日期.
How to format like "31st Dec, 2000" . I have the date in milliseconds.
Java 中是否有任何 API 可以讓我們以這種方式格式化日期?
Is there any API in java that lets us format a date this way?
推薦答案
一個帶switch case的簡單函數,這樣做
A simple function with switch case, do this
Public String getDateSuffix( int day) {
switch (day) {
case 1: case 21: case 31:
return ("st");
case 2: case 22:
return ("nd");
case 3: case 23:
return ("rd");
default:
return ("th");
}
}
這篇關于如何將日期格式化為字符串,例如“2000 年 12 月 31 日"在爪哇的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!