gpt4 book ai didi

android - 日历格式在 Android 中突然和自主改变

转载 作者:行者123 更新时间:2023-11-30 03:31:50 24 4
gpt4 key购买 nike

我的 android 应用程序从几个月前就运行良好。

我用了这样的解析:

String xmlString = Utilities.Unmarshall(appFramework.ordine);

其中 ordine 是类 Servizi 的一个实例:

@Root(name = "Ordine")
public class Servizi {

@Element(name = "data_richiesta")
public Calendar DataRichiesta;

//other elements

public Servizi() {
DataDesideratoDa = Calendar.getInstance();
}
}

我使用了库 org.simpleframework.xml.core.Persister;

几个月前,这产生了这样的东西:

<data_richiesta class="java.util.GregorianCalendar">2012-11-16 17:55:10.216 GMT+01:00</data_richiesta>

而今天它产生:

<data_richiesta class="java.util.GregorianCalendar">2013-06-26 16:26:02.0 CEST</data_richiesta>

我没有在我的应用程序中进行任何更改,但现在我总是获得 CEST 格式,而几个月前我获得了 GMT 格式。

最佳答案

日历.getInstance()

http://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html#getInstance()

Gets a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default locale.

现在是夏天,所以您设备的时区发生了变化。每年,在许多国家/地区,时区实际上每年更改两次:https://en.wikipedia.org/wiki/Daylight_saving_time

您可能应该在代码中指定一个时区,并且可能使用不会更改的 UTC:

Calendar.getInstance(TimeZone.getTimeZone("UTC"));

关于android - 日历格式在 Android 中突然和自主改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17323880/

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