当前位置: 移动技术网 > IT编程>开发语言>Java > 将日期格式化成星期几

将日期格式化成星期几

2019年06月19日  | 移动技术网IT编程  | 我要评论
 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");

}	

  

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网