Android时区问题,困惑

Android时区问题,困惑,android,timezone,datetimeoffset,Android,Timezone,Datetimeoffset,我有一个这样的日期,我自己创造的,6月21日星期二14:47:37 GMT+2016年5:30。我使用日历创建它。其中,用户选择一个日期,我将其保存为日历中的毫秒。 当我发送它时,发送它,我再次创建一个日历实例,将保存的毫秒放入其中,并获得如下日期: Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getDefault()); calendar.setTimeInMillis(SS

我有一个这样的日期,我自己创造的,6月21日星期二14:47:37 GMT+2016年5:30。我使用日历创建它。其中,用户选择一个日期,我将其保存为日历中的毫秒。 当我发送它时,发送它,我再次创建一个日历实例,将保存的毫秒放入其中,并获得如下日期:

Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getDefault());
    calendar.setTimeInMillis(SSPreferences.getDate());
现在,在从日历中获取日期时,我执行以下操作:

calendar.getTime()//This is what I send to server.
我将它发送到服务器,但当服务器向我发送日期时,总是比我的时间早5.5小时

我知道我的时间是格林尼治标准时间+5:50。那么服务器在做什么呢? 如何发送日期,以便返回与发送到服务器的日期相同的日期

感谢您的帮助。 谢谢检查这个

static final String DATEFORMAT = "yyyy-MM-dd HH:mm:ss"

public static Date GetUTCdatetimeAsDate()
{
    //note: doesn't check for null
    return StringDateToDate(GetUTCdatetimeAsString());
}

public static String GetUTCdatetimeAsString()
{
    final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    final String utcTime = sdf.format(new Date());

    return utcTime;
}

public static Date StringDateToDate(String StrDate)
{
    Date dateToReturn = null;
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);

    try
    {
        dateToReturn = (Date)dateFormat.parse(StrDate);
    }
    catch (ParseException e)
    {
        e.printStackTrace();
    }

    return dateToReturn;
}

最后,我通过从本地时区添加/减去rawOffSet解决了这个问题

    TimeZone timeZone = TimeZone.getDefault();
    int offset = timeZone.getOffset(SSPreferences.getDate());
    WriteLog.Print("offset is "+offset);
    long newtime = SSPreferences.getDate() + offset;
    calendar.setTimeInMillis(newtime);

获取UTC时间并以服务器或毫秒为单位“这是我发送到服务器的内容。”-如何将其发送到服务器?如何将日期发送到服务器?是否使用httpurlconnection将其发送到php脚本?还有什么?@JonSkeet--calendar.getTime()只调用
calendar.getTime()
不会向服务器发送任何内容。您是如何将其发送到服务器的?服务器对其做了什么?您是如何从服务器接收值的?你得到的毫秒值是多少?这里缺少很多信息。