I'm trying to obtain the time using ZonedDateTime.ofInstant giving a specific date-time, however i've noticed that in some ocasions the result given doesn't come with seconds in it. Code Example representing the situation i'm working on
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a long variable for milliseconds
//this is the same as "2022-01-31T00:00:00.00Z"
long milliseconds1 = 1643587200000L;
long milliseconds2 = 1643587201000L;
// get Instant using ofEpochMilli() method
Instant instant1
= Instant.ofEpochMilli(milliseconds1);
// create Instant object
Instant instant2
= Instant.ofEpochMilli(milliseconds2);
// create a ZonID
ZoneId zone = ZoneId.of("Europe/Lisbon");
// apply ofInstant method
// of ZonedDateTime class
ZonedDateTime zt1 = ZonedDateTime
.ofInstant(instant1, zone);
ZonedDateTime zt2 = ZonedDateTime
.ofInstant(instant2, zone);
// print the result
System.out.println("ZonedDateTime is " + zt1);
System.out.println("ZonedDateTime is " + zt2);
}
}
The result of this code execution is as follows:
ZonedDateTime is 2022-01-31T00:00Z[Europe/Lisbon]
ZonedDateTime is 2022-01-31T00:00:01Z[Europe/Lisbon]
I need to get the seconds that are not showing in the first result but i can't understand why it's not showing Is there a reason for ZonedDateTime.ofInstant to not give the full time, or is there a different way to get the time to a specific time zone in YYYY-MM-DD:HH:MM:SS?