如何从Android中的选定日期月份和年份获取星期几名称? [英] How to get day of week name from selected date month and year in Android?
本文介绍了如何从Android中的选定日期月份和年份获取星期几名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了下面的代码,但是它给了我两天前的星期几的名称.
I tried the below code but it gives me the name of the day of week two days ago.
DatePicker picker;
int date = picker.DayOfMonth;
int month = (picker.Month + 1);//month is 0 based
int year = picker.Year;
SimpleDateFormat simpledateformat = new SimpleDateFormat("EEE");
Date dt = new Date(year, month, date);
推荐答案
首先使用 SimpleDateFormat
使用 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE");
获取星期几的日期
EEEE
->所在的星期几
WHERE EEEE
-> Day name in week
示例代码
SimpleDateFormat inFormat = new SimpleDateFormat("dd-MM-yyyy");
try {
Date myDate = inFormat.parse(date+"-"+month+"-"+year);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE");
String dayName=simpleDateFormat.format(myDate);
} catch (ParseException e) {
e.printStackTrace();
}
这篇关于如何从Android中的选定日期月份和年份获取星期几名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文