JtecX JtecX - 1 year ago 102
Android Question

Android - Error SimpleDateFormat Unknown pattern character 'u'

Please help:
Android Studio Logcat:

java.lang.IllegalArgumentException: Unknown pattern character 'u'

Here is my Code:

long ticket = 1473808310826L;
SimpleDateFormat sdf = new SimpleDateFormat("u");
String test = sdf.format(ticket);

using: jdk1.8

u is used in the Android Documentation

Trying to use:
Day number of week (1 = Monday, ..., 7 = Sunday)

Answer Source

The documentation of SimpleDateFormat is misleading.

There is no u pattern character in Android.

From the source code of 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 + "'");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download