时间长的负面

时间:2017-04-26 09:31:56

标签: java android

嘿,我有一个问题:

日志:

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:00:00它正常而不是negatif

1 个答案:

答案 0 :(得分:-1)

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

试试这个,它可能对你有所帮助。它对我来说很好。