2012-01-18 55 views
0

我正在編寫一個移動應用程序,並且我需要安裝Android來存儲變量,並在用戶按下按鈕開始跟蹤其位置時將日期時間發送到遠程服務器。用戶開始在Android中跟蹤位置的日期時間

我在做什麼,現在是String date = DateFormat.getDateFormat(this).toString().concat(DateFormat.getTimeFormat(this).toString());但當然這是行不通的,因爲它插入這個遠程DB [email protected]

我做的來電和短信數據同樣的事情,但在這種情況下,我正在查詢內容解析器並從那裏獲取日期,但是對於位置我有點卡住..

非常感謝您的回覆。

Best, Manuel。

回答

1

也許你喜歡用轉換爲長UTC時間工作。

Calendar calendar = Calendar.getInstance(); 
long utcTime = calendar.getTimeInMillis() - calendar.getTimeZone().getDSTSavings(); 
+0

完美!因爲我意識到在其他表格中,我也使用來自內容提供者的UTC時間。非常感謝! – noloman 2012-01-18 22:20:13

2

DateFormat用於格式化或解析日期。我認爲format(..)方法可以幫助您:

String myFormattedDate = DateFormat.getDateFormat(this).format(new Date()); 

Date類收到實際時間。 DateFormat僅用於將日期格式化爲更具可讀性的格式。

Date()構造的Javadoc:

分配Date對象,並且使得它代表測得的到最近的毫秒在其被分配的時間,對其進行初始化。

如果要格式化的日期轉換回一個Date對象(所以你可以使用它)DateFormat.parse(..)可以幫助你;-)

+0

非常感謝,以及如果我也想包括在那裏的時間,所以它實際上就像一個日期時間? – noloman 2012-01-18 22:08:05