出于某种原因,我的时钟只有 2 个小时,而我只运行了几秒钟。以下是时间戳和代码的结果:
08-12 01:03:47.858: I/System.out(2856): 1344722627872
08-12 01:03:51.198: I/System.out(2856): 1344722631206
08-12 01:03:54.698: I/System.out(2856): 3334
08-12 01:03:54.758: I/System.out(2856): 02:00:03
public static String getDate(long milliSeconds, String dateFormat) {
DateFormat formatter = new SimpleDateFormat(dateFormat);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime()); }
这是调用的完整代码:
// Click Listener for Check In\Out Button
checkIn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Check Out
myVib.vibrate(10);
if (clicked == true) {
timeStampWhenOut = System.currentTimeMillis();
killcheck = true;
checkedStatus = "Check In";
checkIn.setText(checkedStatus);
long getShiftLength = ShiftLength(timeStampWhenIn,
timeStampWhenOut);
System.out.println(timeStampWhenOut);
System.out.println(getShiftLength);
System.out.println(getDate(getShiftLength, "hh:mm:ss"));
clicked = false;
wasShift = true;
// Check In
} else if (clicked == false) {
timeStampWhenIn = System.currentTimeMillis();
System.out.println(timeStampWhenIn);
checkedStatus = "Check Out";
checkIn.setText(checkedStatus);
killcheck = false;
clicked = true;
}
}
});
为什么时间错了?