Warning: I see that the comments have been deleted, if it comes to this
question to apply it to Android this is not your answer as the
Original question to mutated.
In this link you can see some data to do ect verifications.
link
link
import java.util.Date;
import java.sql.Timestamp;
public static void main (String[] args) throws java.lang.Exception {
Timestamp stamp = new Timestamp(1471212000);
Date date_f = new Date(stamp.getTime() * 1000L);
System.out.println(date_f.toString());
System.out.println(date_f);
}
The toString
method applies the default time zone of the JVM, for java.util.Data this does not have time for the zone.
With java.time
you can manage time in several ways:
.
import java.time.ZoneOffset;
import java.time.OffsetDateTime;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public static void main (String[] args) throws java.lang.Exception {
Instant instant = Instant.now();
ZoneOffset zone_offset = ZoneOffset.of( "+01:00" );
OffsetDateTime offeset_date_time = OffsetDateTime.ofInstant( instant , zone_offset );
System.out.println(instant.toString());
System.out.println(offeset_date_time.toString());
ZoneId zone_id = ZoneId.of( "America/Los_Angeles" ); // <- Mirar shortIds link
ZonedDateTime zoned_date_time = ZonedDateTime.ofInstant( instant , zone_id );
System.out.println(zoned_date_time.toString());
//Formato ejemplo
DateTimeFormatter formatterOutput = DateTimeFormatter.ISO_DATE_TIME; // <-- Mirar link DateTimeFormatter predefined
String output = formatterOutput.format(zoned_date_time);
}
shortdIds Link
DateTimeFormatter predefined Link
link
Update:
I had already commented that this could happen, in a comment in Elenasys' answer, but I'll put it back as an update (due to your new question, which of course leaves a comment, explaining how to update your question).
The result is: date = 1144015200 time = 36000 14-01-1970 24: 0: 36
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds .... 1471212000 seconds - > * 1000L - > setTimeInMillis
, I hope you understand what I want to say, if you do not apply 1000 to setTimeInMillis
will treat the data in the same way and not having 1000 because the dates are different.
try the following, in places where you use setTimeInMillis(dateTimestamp)
:
.setTimeInMillis(dateTimestamp * 1000L);