2012-02-09 144 views
0

我有一個英文工作的應用程序。android更改語言日期

但是,當我將設備的語言更改爲法語我得到一個異常。

在活動中我做到以下幾點:

send(new Date.tostring()); 

並將其發送給另一個活動,我想拿到追溯。

public method (String stringDate){ 
new Date(date.parse(stringDate)); 
} 

只要我在英語模式下,這工作正常。 但是,當我去設置和語言更改爲法語(所以我的應用程序將用法語) 我得到一個illegalargumentException,他不能解析字符串的日期。

任何幫助將不勝感激!

回答

2

而不是發送字符串構造日期,您應該使用getTime()方法發送毫秒作爲長的值。它是傳遞日期並重構它的正確方法。例如,

派:

long value = new Date().getTime(); 

重建:

Date d = new Date(value); 
0

它與在不同語言/語言環境中使用的(可能)不同日期系統有關嗎?

例如:

Imagine the following date: 02/04/03 
Which does it mean? 
    2nd of April 2003 (European style) 
    4th of February 2003 (USA style) 
    3rd of April 2002 

(摘自:http://www.w3.org/QA/Tips/iso-date

注:我從來沒有爲Android開發。這只是猜測