java.text.ParseException:Unparseable date:" 11:49:28முற்பகல்"

时间:2018-02-20 11:53:38

标签: java android

如果在Android日期中选择了泰米尔语,AM应该看起来像"முற்பகல்"。 为此,将如何解析日期?

com.carepredict.cp_native W/System.err: java.text.ParseException: Unparseable date: "11:49:28 முற்பகல்" (at offset 9)
02-20 17:19:28.310 22978-22978/com.carepredict.cp_native W/System.err:     at java.text.DateFormat.parse(DateFormat.java:579)
        at com.carepredict.cp_native.holders.AlertListitemHolder.bindFloors(AlertListitemHolder.java:173)
        at com.carepredict.cp_native.adapters.AlertListAdapter.onBindViewHolder(AlertListAdapter.java:41)
        at com.carepredict.cp_native.adapters.AlertListAdapter.onBindViewHolder(AlertListAdapter.java:15)

2 个答案:

答案 0 :(得分:0)

您需要使用replace功能,这将有助于

像这样使用

String date = ("11:49:28 முற்பகல்").replace("முற்பகல்", "am");
String date1 = ("11:49:28 பிற்பகல்").replace("பிற்பகல்", "pm");

答案 1 :(得分:0)

试试这个: -

<!--Main-->
    //...
    try {
       memcached = new Memcached ();
    }
    catch (Exception e) {
       memcached  = null;
    }
    //...
  

你可以再次将它添加到字符串中,无论你想要什么......比如

splitT [0]是这个值&#34; 13:24:40&#34;和splitT [1]将有你的特殊字符串,即&#34;முற்பகல்&#34;

<!--Memcached-->
public class Memcached {
private MemcachedClient memcachedClient;
private boolean connected;

public Memcached () throws Exception {
    setConnected(true);

    try {
        AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
                new PlainCallbackHandler(System.getenv("MEMCACHEDCLOUD_USERNAME"),
                    System.getenv("MEMCACHEDCLOUD_PASSWORD")
                )
        );

        setMemcachedClient(new MemcachedClient(
                new ConnectionFactoryBuilder()
                        .setDaemon(true)
                        .setFailureMode(FailureMode.Retry)
                        .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) //this is the line 34 
                        .setAuthDescriptor(ad).build(),
                AddrUtil.getAddresses(System.getenv("MEMCACHEDCLOUD_SERVERS"))
        ));
    } catch (Exception ex) {
        // the Memcached client could not be initialized
        setConnected(false);
        throw new Exception ("{\"ErrorCode\":20,\"Portal\":\"Memcached\",\"ResponseCode\":\"\",\"Message\":\""
                + ex.getMessage() + "\"}");
    }
}

public String get (String service, String fromCurrency, String toCurrency) {
    if (!isConnected()) {
        return null;
    }

    try {
        return (String) getMemcachedClient().get(service + ";" + fromCurrency + ";" + toCurrency);
    }
    catch (Exception e) {
        return null;
    }
}

public boolean set (String service, String fromCurrency, String toCurrency, String value) {
    if (!isConnected()) {
        return false;
    }

    try {
        double hour = Double.parseDouble(System.getenv("TIME_CACHE_HOUR"));
        getMemcachedClient().set(service + ";" + fromCurrency + ";" + toCurrency, (int)(60 * 60 * hour), value);

        return true;
    }catch (Exception e) {
        return false;
    }
}

public boolean isConnected () {
    return this.connected;
}

private void setConnected (boolean connected) {
    this.connected = connected;
}

private MemcachedClient getMemcachedClient () {
    return this.memcachedClient;
}

private void setMemcachedClient (MemcachedClient memcachedClient) {
    this.memcachedClient = memcachedClient;
}

修改: - 为时间(上午或下午的小时)分配正确的本地语言,在这种情况下为其泰米尔语......做这个检查..

String myDateString = "13:24:40 முற்பகல்";
String[] splitT       = myDateString.split(" ");

LocalTime localTime = LocalTime.parse(splitT[0], 
                      DateTimeFormatter.ofPattern("HH:mm:ss"));

int hour = localTime.get(ChronoField.CLOCK_HOUR_OF_DAY);
int minute = localTime.get(ChronoField.MINUTE_OF_HOUR);
int second = localTime.get(ChronoField.SECOND_OF_MINUTE);