我正在尝试使用下面的代码片段从.dat文件打印出日期/时间列表,但它总是具有相同的输出,我不知道为什么。
SimpleDateFormat TimeStampFormat = new SimpleDateFormat("yyyy:dd:hh:mm:ss:");
long measurement = 0;
for (i=0; i<MeasurementLength; i++ ){
databyte = ReadFilterInputPort();
measurement = measurement | (databyte & 0xFF);
if (i != MeasurementLength-1)
measurement = measurement << 8;
} // for
TimeStampA.setTimeInMillis(measurementA);
System.out.println(measurementA);
System.out.printf("%-22s\n",TimeStampFormat.format(TimeStampA.getTime()));
例如,几行的输出是:
(输入) 1300828035071
(输出) 2011:22:05:07:15
(输入)1300828035073
(输出)2011:22:05:07:15
我做错了什么,或者这是给定输入的正确输出?
答案 0 :(得分:3)
尝试以下代码
try {
long measureA = System.currentTimeMillis();// You can assign your exact date which is in long format
Date date = new Date(measureA);
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");
System.out.println(sdf.format(date));
sdf = new SimpleDateFormat("E MMM dd yyyy");
System.out.println(sdf.format(date));
}catch(Exception e)
{
e.printStackTrace();
}
您可以根据需要更改格式字符串