[英]Android : Error SimpleDateFormat Unknown pattern character 'u'
I use java 1.7.25 but found this error. 我使用java 1.7.25但发现此错误。 what should I do?
我该怎么办?
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Unknown pattern character 'u'
at java.text.SimpleDateFormat.validateFormat(SimpleDateFormat.java:264)
at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:319)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:365)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:249)
Here is my code 这是我的代码
public static int getDayNumberOfWeek(int day, String monthString, int yyyy) {
//http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
int dayNumberOfWeek = 1;
final String inputFormat = "MMM/dd/yyyy";
final String outputFormat = "u";
String dayString2Digit = DateTimeHelper.getTwoDigit(day);
String inputTimeStamp = monthString + "/" + dayString2Digit + "/" + String.valueOf(yyyy);
try {
dayNumberOfWeek =Integer.valueOf(TimeStampConverter(inputFormat, inputTimeStamp,
outputFormat));
}
catch (ParseException e) {
e.printStackTrace();
}
return dayNumberOfWeek;
}
I use java 1.7.25
我用的是java 1.7.25
No, you don't - not if you're running on Android. 不,你没有 - 如果你在Android上运行则不行。 You need to look at the Android documentation, not the Java 7 docs.
您需要查看Android文档,而不是Java 7文档。
If you look at the Android SimpleDateFormat
documentation you'll see that u
isn't listed there. 如果你查看Android
SimpleDateFormat
文档,你会发现u
没有在那里列出。 I don't believe there's a format pattern character for "day of week as a number" in Android. 我不相信Android中“星期几作为数字”的格式模式字符。
Were you really looking for that though? 你真的在寻找那个吗? If you just want the day of the week as a number (without anything else) you can always use
如果您只想将星期几作为数字(没有其他任何东西),您可以随时使用
String text = String.valueOf(calendar.get(Calendar.DAY_OF_WEEK));
If you're using android, then you're not using Java 1.7.25. 如果您使用的是android,那么您就不使用Java 1.7.25了。 See the android documentation : there's no support for
u
in SimpleDateFormat. 请参阅android文档 :在SimpleDateFormat中不支持
u
。
I'm guessing your problem is going to be in your TimeStampConverter
class where you're passing in that "u" as the outputFormat
. 我猜你的问题将出现在你的
TimeStampConverter
类中,你传递的是“u”作为outputFormat
。 "u" is not a valid format character in SimpleDateFormat
and you must be constructing a format string that contains it. “u”不是
SimpleDateFormat
的有效格式字符,您必须构造包含它的格式字符串。
If you need to use the "u" as a literal, you'll need to enclose it in single quotes. 如果您需要将“u”用作文字,则需要将其用单引号括起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.