
image.png
上面圖中,首先怎么獲取周幾:這個(gè)比較簡(jiǎn)單
/**
* 獲取當(dāng)前是周幾
* @param time 毫秒
* @return string
*/
public static String getDateForEEETime(long time) {
Date d = new Date(time);
SimpleDateFormat sf = new SimpleDateFormat("EEE");
return sf.format(d);
}
怎么獲取圖片中的年月日格式呢 MMM d | yyyy 注意如果想獲取英文要指定為 Locale.ENGLISH
public static String getDateForMMMTime(long time) {
//注意傳入的要是一個(gè)毫秒
Date d = new Date(time);
SimpleDateFormat sf = new SimpleDateFormat("MMM d | yyyy",Locale.ENGLISH);
return sf.format(d);
}
當(dāng)然還有一些常規(guī)的如:
SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日"); 獲取2019年05月14日
等,這里就不過多贅述了.
說明-關(guān)于SimpleDateFormat支持的時(shí)間格式:
* G: 公元 時(shí)代,例如AD公元
* yy: 年的后2位
* yyyy: 完整年
* MM: 月,顯示為1-12
* MMM: 月,顯示為英文月份簡(jiǎn)寫,如 Jan
* MMMM: 月,顯示為英文月份全稱,如 Janualy
* dd: 日,2位數(shù)表示,如02
* d: 日,1-2位顯示,如 2
* EEE: 簡(jiǎn)寫星期幾,如Sun
* EEEE: 全寫星期幾,如Sunday
* aa: 上下午,AM/PM
* H: 時(shí),24小時(shí)制,0-23
* K:時(shí),12小時(shí)制,0-11
* m: 分,1-2位
* mm: 分,2位
* s: 秒,1-2位
* ss: 秒,2位
* S: 毫秒