Android SimpleDataFormat子类将年份增加1900
我已经创建了Android SimpleDataFormat子类将年份增加1900,android,date,datepicker,Android,Date,Datepicker,我已经创建了SimpleDateFormat的几个子类,以简化在Android上处理Azure提要的过程。其中一项是: public class ISO8601TLDateFormat extends SimpleDateFormat { private static String mISO8601T = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; public ISO8601TLDateFormat() { super(mISO8601T);
SimpleDateFormat
的几个子类,以简化在Android上处理Azure提要的过程。其中一项是:
public class ISO8601TLDateFormat extends SimpleDateFormat {
private static String mISO8601T = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
public ISO8601TLDateFormat() {
super(mISO8601T);
}
public ISO8601TLDateFormat(Locale inLocale) {
super(mISO8601T, inLocale);
}
}
正如您所见,其目的是生成或解释如下所示的日期
2012-03-17T00:00:00.000+0100
这正是Azure服务所期望的。但是,当我输入由日期选择器构建的对象时,因此:
mDate = new Date(mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
ISO8601TLDateFormat
的输出为
3912-03-17T00:00:00.000+0100
正如你所看到的,这一年比我,或者未来任何人所需要的都多1900英镑。我已经仔细检查了
Date
对象在它到Azure提要系统的整个过程中,它报告它的日期是2012年,这是我所期望的。为什么SimpleDateFormat
会中断?问题是Date
的构造函数没有收到您期望的结果。摘自java:
你需要记住,你构造的日期是1900年1月1日。可能有一个日期,因为它的年份是1900年。我认为这里没有足够的信息。。。我们需要知道您对SimpleDateFormat的具体调用,以生成错误的输出以及它是如何初始化的,等等。我已经得到了答案(如下),但我将澄清我是如何错误地构造了我的
日期
对象的。谢谢您——那么,我假设日期35; getYear()
还提供年份减去1900?(这肯定给了我2012年)。。只要阅读文档,你就会发现你是对的。介意我在你的答案中添加以下链接吗?
public Date(int year,
int month,
int date)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).
Allocates a Date object and initializes it so that it represents midnight, local time, at the beginning of the day specified by the year, month, and date arguments.
Parameters:
year - the year minus 1900.
month - the month between 0-11.
date - the day of the month between 1-31.