逻辑猫:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Unknown pattern character 'u'
这是我的密码:
long ticket = 1473808310826L;
SimpleDateFormat sdf = new SimpleDateFormat("u");
String test = sdf.format(ticket);
使用:JDK 8
u
用于文档 of SimpleDateFormat
一周天数(1 =星期一,.,7=星期日)
发布于 2016-09-16 19:11:15
“纽约时报”( The 文档 of SimpleDateFormat
)具有误导性(截至2016年9月16日,对未来读者而言)。
安卓中没有u
模式字符。
来自SimpleDateFormat
的源代码
static final String PATTERN_CHARS = "GyMdkHmsSEDFwWahKzZLc";
// ...
private void validatePatternCharacter(char format) {
int index = PATTERN_CHARS.indexOf(format);
if (index == -1) {
throw new IllegalArgumentException("Unknown pattern character '"
+ format + "'");
}
}
为了一周中的这一天,你可以这样做:
Calendar calendar = Calendar.getInstance();
// if you do not wish to use the current time, but a specific one
// calendar.setTimeInMillis(yourTimeInMillis);
switch (calendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
// monday
break;
case Calendar.TUESDAY:
// tuesday
break;
// ...
}
https://stackoverflow.com/questions/39538275
复制相似问题