我尝试了下面的代码,但它给了我两天前星期几的名称。
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");
在本周获得国庆节的名称
WHERE EEEE
-> 周中的日期名称
示例代码
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();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句