2016-06-21 4 views
-1

私はこのような日付を持っていますTue Jun 21 14:47:37 GMT + 05:30 2016、私は自分自身を作成し​​ます。カレンダーを使って作成します。ユーザーが日付を選択し、カレンダーからミリ秒単位で保存します。 私はそれを送って、それを送信、私は再びそこに保存されたミリ秒を入れカレンダーのインスタンスを作成し、このような日付を取得:Androidタイムゾーンの問題、混乱しました

calendar.getTime()//This is what I send to server. 
:カレンダーから日付を取得しながら、今

Calendar calendar = Calendar.getInstance(); 
    calendar.setTimeZone(TimeZone.getDefault()); 
    calendar.setTimeInMillis(SSPreferences.getDate()); 

を私はこれを行います

私はそれをサーバーに送信しますが、サーバーが私に日付を送信すると、私の時間の前には常に5.5時間です。

私は自分の時間がGMT + 5:50であることを知っています。だから、サーバーはその面で何をしているのですか? 日付を送信すると、サーバーに送信した日付と同じ日付が返されます。

何か助けていただければ幸いです。

+0

時間を取得してサーバーまたはミリ秒で保持 – Sreekanth

+0

「これはサーバーに送信するものです。」 - *どうやってサーバーに送りますか? –

+0

どのように日付をサーバーに送信していますか? httpurlconnectionを使ってPHPスクリプトに送りますか?他に何か? –

答えて

0

チェックこの

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; 
} 
0

おかげで最後に私は、ローカルタイムゾーンからrawOffSetを差し引い/追加することで問題を解決しました。

TimeZone timeZone = TimeZone.getDefault(); 
    int offset = timeZone.getOffset(SSPreferences.getDate()); 
    WriteLog.Print("offset is "+offset); 
    long newtime = SSPreferences.getDate() + offset; 
    calendar.setTimeInMillis(newtime); 
関連する問題