2013-01-11 36 views

回答

5

我知道它不完全是你問的,但你也可以從網絡提供商(移動電話網絡)獲得時間。

你試過

LocationManager locMan = (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE); 
long time = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime(); 

返回以毫秒的時間。

所以你不需要互聯網連接或JSON解析,XML ...

希望這有助於在某種程度上,

托比亞斯

+0

。很多的answer.This千恩萬謝是非常有幫助... –

+0

它返回顯示java.lang.NullPointerException,什麼是錯? – NPE

0

我有一個公用的Web服務,當我「問「通過SOAP到服務器,他們回到我的日期。

@WebMethod(operationName = "getDateTime") 
public byte[] getDateTime() { 
    UtilWS.showIpClient(wsContext); 

    String format = "yyyy-MM-dd HH:mm:ss.SSS"; 
    SimpleDateFormat sdf = new SimpleDateFormat(format, 
      Locale.US); 
    String data = sdf.format(new Date(System.currentTimeMillis())); 

    System.out.println("== Date Requisiton: " + data); 
    return data.getBytes(); 
} 

在我的客戶端:

byte[] b = CommWS.send(getApplicationContext(), "UtilWS", "getDateTime"); 
String server_date = new String(b); 

的CommWS是我的類,它實現與服務器的SOAP通信。

CYA,
Bertan

相關問題