Q:

Timestamp format not showing different values

I am trying to print out a list of dates/times from a .dat file with the code snippet below, but it always has the same output and I don't know why.
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()));

For example, the output of a few lines is:
(input)
1300828035071
(output)
2011:22:05:07:15      
(input)    1300828035073
(output) 2011:22:05:07:15 
Am I doing something wrong or would this be the correct output for the given input?

A:

Try below code
   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();

        }

You can change format string according to your need

