2017-04-26 25 views
-1

嘿,我有一個問題:時間長負

日誌:

04-26 11:29:09.332 21657-21784/com.grou D/answer: -3600000 
04-26 11:29:09.332 21657-21784/com.grou D/answer: 12:00:00 

代碼:

SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss"); 
Date parsedDate = dateFormat.parse(TimeEnd); 
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime()); 
tsTimeEnd = timestamp.getTime(); 
Log.d("answer",Long.toString(timestamp.getTime())); 
timestamp.setTime(tsTimeEnd); 
Log.d("answer",dateFormat.format(timestamp)); 

爲什麼-3600000? :(

解決方案:

我是在24小時內,我把HH或它的HH如此12:00:00這是正常的比negatif

+0

究竟是你想要做的B/N兩個日期嗎? – Rajasekhar

+0

http://stackoverflow.com/questions/15003498/why-does-simpledateformat-parse-gettime-return-an-incorrect - 負值 –

+0

Nop不工作相同的問題小時是:-1.0 – Royalxm

回答

0
public static long getMillisFromDate(String date) { 
    SimpleDateFormat sdf = new SimpleDateFormat(hh:mm:ss); 
    sdf.setTimeZone(TimeZone.getTimeZone("UTC")); 
    long timeInMilliseconds = 0; 
    try { 
     Date mDate = sdf.parse(date); 
     timeInMilliseconds = mDate.getTime(); 
    } catch (ParseException e) { 
     e.printStackTrace(); 
    } 
     return timeInMilliseconds; 
    } 

嘗試了這一點,它可以幫助你它對我的工作很好

+0

Thx你我解決了我的問題哈哈我在24小時內我把......或者它是HH所以12:00:00這是正常的比negatif – Royalxm