/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Date;
import java.sql.Timestamp;
import java.util.Calendar;
import java.text.SimpleDateFormat;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
Timestamp stamp
= new Timestamp(1471212000); //puede usar un long directamete yo lo uso como contenedor Date date_f
= new Date(stamp.
getTime() * 1000L
);
//System.out.println(date_f.toString());
Date date_test
= new Date(stamp.
getTime());
//esto imprime mas o menos lo mismo que uste publica
//fijese que stamp.getTime() no esta *1000L puede hacer la comprovacion
//en este link:
//http://w...content-available-to-author-only...r.com/timezones?q=1471212000&tz=America%2FNew_York
System.
out.
println(date_test
);
//puede ver que al hacer Date(stamp.getTime() * 1000L); el resultado es similar
//fijese que uno es 1970 y otro 2016 eso es porque uno tiene aplicado *1000L
//he busacado este respuesta igual entiende mejor lo que le digo:
//http://stackoverflow.com/questions/17432735/convert-unix-time-stamp-to-date-in-java
//Saludos!
String miJSONTimeStamp
= "1471212000"; Long miTimeStamp
= Long.
parseLong(miJSONTimeStamp
);
//Define formato de salida deseado.
String formatoDeseado
= "yyyy-MM-dd hh:mm:ss";
//Crea objeto para convertir millisegundos a fecha.
calendar.setTimeInMillis(miTimeStamp);
//aplica formato
String fechaconFormat
= formatter.
format(calendar.
getTime());
System.
out.
println("Test sin *1000L"); System.
out.
println(fechaconFormat
);
///////////////////////////////////
calendar1.setTimeInMillis(miTimeStamp * 1000L); // <-- Aplicamos *1000L
//aplica formato
String fechaconFormat1
= formatter.
format(calendar1.
getTime());
System.
out.
println("Test con *1000L"); System.
out.
println(fechaconFormat1
); }
}