1

我正在尝试使用下面的代码片段从 .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

我做错了什么还是给定输入的正确输出?

4

1 回答 1

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

        }

您可以根据需要更改格式字符串

于 2013-02-19T06:22:32.243 回答