2017-04-26 2 views
-1

Hey, ich habe ein Problem:Zeit lang negativ

log:

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 

Code:

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)); 

warum -3.600.000 ?? :(

Lösung:

i innerhalb von 24 Stunden bin setzen i hh oder es ist HH so 0.00.00 es normal ist, als ist negatif

+0

Genau das, was Sie tun möchten, b/n zwei Termine? – Rajasekhar

+0

http://StackOverflow.com/Questions/15003498/Why-does-SimpledateFormat-Parse-Gettime-Return-an-incorrect -negative-Wert –

+0

Nop nicht funktioniert gleiche Problem Stunde ist: -1.0 – Royalxm

Antwort

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

dies ausprobieren, kann es Ihnen helfen, Es funktioniert gut für mich.

+0

Thx Sie ich löste mein Problem lol ich bin in 24 Stunden ich stelle hh oder es ist HH so 12:00:00 es ist normal als negativ ist – Royalxm