android – SimpleDateFormat子类在这一年增加了1900

android – SimpleDateFormat子类在这一年增加了1900,第1张

概述我已经创建了几个SimpleDateFormat的子类来简化处理我在 Android上谈论的Azure提要.其中一个如下: public class ISO8601TLDateFormat extends SimpleDateFormat { private static String mISO8601T = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; publ 我已经创建了几个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服务所期望的.但是,当我输入从DatePicker构造的Date对象时:

mDate = new Date(mDatePicker.getYear(),mDatePicker.getMonth(),mDatePicker.getDayOfMonth());

ISO8601TLDateFormat的输出是

3912-03-17T00:00:00.000 0100

正如你所看到的,这一年比我更多,或者不是未来的任何人都需要.我已经仔细检查了Date对象到Azure Feed系统的整个过程,它报告的日期是2012年,这是我所期望的.为什么SimpleDateFormat会破坏?

解决方法 问题是Date的构造函数没有得到你期望的结果.取自java documentation:

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,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,and date arguments.Parameters:year - the year minus 1900.month - the month between 0-11.date - the day of the month between 1-31.

你需要记住,你构造的日期是0,1,是1900年1月1日.

总结

以上是内存溢出为你收集整理的android – SimpleDateFormat子类在这一年增加了1900全部内容,希望文章能够帮你解决android – SimpleDateFormat子类在这一年增加了1900所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1128562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存