将日期格式化成星期几
程序员文章站
2022-03-19 23:42:59
传入日期 ......
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");
}
上一篇: php错误调试