Android:错误SimpleDateFormat未知模式字符'u' [英] Android : Error SimpleDateFormat Unknown pattern character 'u'

查看:176
本文介绍了Android:错误SimpleDateFormat未知模式字符'u'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用java 1.7.25
但发现此错误。我该怎么办?

I use java 1.7.25 but found this error. 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)

这是我的代码

    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;
}


推荐答案


我使用java 1.7.25

I use java 1.7.25

不,你没有 - 如果你在Android上运行则不行。您需要查看Android文档,而不是Java 7文档。

No, you don't - not if you're running on Android. You need to look at the Android documentation, not the Java 7 docs.

如果你看一下 Android SimpleDateFormat 文档你会看到 u 。我不相信Android中星期几作为数字的格式模式字符。

If you look at the Android SimpleDateFormat documentation you'll see that u isn't listed there. I don't believe there's a format pattern character for "day of week as a number" in 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));

这篇关于Android:错误SimpleDateFormat未知模式字符'u'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆