gpt4 book ai didi

java - Android 2.0 模拟器中奇怪的解析日期字符串错误

转载 作者:行者123 更新时间:2023-12-01 16:04:46 24 4
gpt4 key购买 nike

我有一个简单的测试代码用于测试 SimpleDateFormat。此代码在 Eclipse 和 Android 1.5 模拟器上运行良好,但在 Android 2.0 模拟器上失败。有谁知道为什么?谢谢。

public class TemplateActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText(R.string.hello);
setContentView(tv);

SimpleDateFormat format =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");

String dateStr = "Mon, 17 May 2010 01:45:41 GMT";

try {
Date parsed = format.parse(dateStr);
Log.v("Test", parsed.toString());
} catch (ParseException pe) {
Log.v("Test", "ERROR: Cannot parse \"" + dateStr + "\"");
}

}
}

日志消息:

V/Test(  400): ERROR: Cannot parse "Mon, 17 May 2010 01:45:41 GMT"

最佳答案

回复 Skrud,

我尝试了“EEE,dd MMM yyyy HH:mm:ss z”,但收到了相同的错误消息。

我也尝试过

SimpleDateFormat format =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);

它有效。但是系统每次调用都需要很长时间来加载 en_US 的时区名称:

I/Resources(  471): Loaded time zone names for en_US in 1904ms.
D/dalvikvm( 471): GC freed 10658 objects / 486232 bytes in 88ms
I/Resources( 471): Loaded time zone names for en_US in 1400ms.
I/Resources( 471): Loaded time zone names for en_US in 1260ms.
D/dalvikvm( 471): GC freed 10615 objects / 491920 bytes in 91ms
I/Resources( 471): Loaded time zone names for en_US in 1360ms.
I/Resources( 471): Loaded time zone names for en_US in 1232ms.
D/dalvikvm( 471): GC freed 10623 objects / 460544 bytes in 91ms
I/Resources( 471): Loaded time zone names for en_US in 1344ms.
I/Resources( 471): Loaded time zone names for en_US in 1228ms.

我应该做什么?

关于java - Android 2.0 模拟器中奇怪的解析日期字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2853058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com