有人在Android上使用jodatime吗?我逼近无踪。
package test.journal.help;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.Days;
import android.app.Activity;
import android.os.Bundle;
public class journaltester extends Activity {
/** Called when the activity is first created. */
private Date today = new Date();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Days days = Days.daysBetween(new DateTime(today), new DateTime(today));
setContentView(R.layout.main);
}
}
今天的价值:“ 2010年8月7日星期六/美国/纽约”
好吧,进步了...
根据kiwidoc在org.joda.time.DateTimeZone.getDefault()处获取stackoverflow错误,这是如果zone为null引起的。
public static DateTimeZone getDefault() {
DateTimeZone zone = cDefault;
if (zone == null) {
synchronized(DateTimeZone.class) {
zone = cDefault;
if (zone == null) {
DateTimeZone temp = null;
try {
try {
temp = forID(System.getProperty("user.timezone"));
} catch (RuntimeException ex) {
// ignored
}
if (temp == null) {
temp = forTimeZone(TimeZone.getDefault());
}
} catch (IllegalArgumentException ex) {
// ignored
}
if (temp == null) {
temp = UTC;
}
cDefault = zone = temp;
}
} //LINE 147
}
return zone;
}
这是堆栈:
Thread [<3> main] (Suspended (exception StackOverflowError))
DateTimeZone.getDefault() line: 147
ISOChronology.getInstance() line: 86
DateTimeUtils.getChronology(Chronology) line: 231
DateConverter(AbstractConverter).getChronology(Object, Chronology) line: 82
DateTime(BaseDateTime).<init>(Object, Chronology) line: 170
DateTime.<init>(Object) line: 168
PlantsCursorAdapter.newView(Context, Cursor, ViewGroup) line: 71
PlantsCursorAdapter(CursorAdapter).getView(int, View, ViewGroup) line: 182
最佳答案
这是因为user.timezone
系统属性为null。见http://sourceforge.net/tracker/?func=detail&aid=3056104&group_id=97367&atid=617889