2017-04-26 1 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를 넣어 정도 12시 0분 0초가

+0

두 날짜로 b/n 할 정확히 무엇입니까? – Rajasekhar

+0

http://stackoverflow.com/questions/15003498/why-does-simpledateformat-parse-gettime-return-an-incorrect - 음수 값 –

+0

작동하지 않는 동일한 문제 시간 : -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; 
    } 

이 밖으로 시도 negatif보다 정상은 HH있어에있어

, 그것은 당신을 도울 수 있습니다 . 나를 위해 잘 작동합니다.

+0

Thx 너는 내 문제를 해결했다. LOL. 나는 24 시간 안에 내가 hh를 넣었다. HH 그래서 네가티브보다 12시 00 분에 정상입니다. – Royalxm