欢迎来到我的博客

将日期格式化成星期几

 public static String dayForWeek(String pTime) throws Throwable {  
	        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
	        Date tmpDate = format.parse(pTime);  
	        Calendar cal = Calendar.getInstance(); 
	        String[] weekDays = { "日", "一", "二", "三", "四", "五", "六" };
	        try {
	            cal.setTime(tmpDate);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
	        if (w < 0)
	            w = 0;
	        return weekDays[w];

	    }  

  传入日期

public static void main(String[] args) throws Throwable {

		 String a = dayForWeek("2019-06-29 09:44:1");

}	

  

posted @ 2019-06-18 16:46  八千轮回  阅读(2455)  评论(0编辑  收藏  举报
人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。