Sathish David Kumar N
asked on
how to get the GMT time zone return format as timestamp
how to get the GMT time zone return format as timestamp
static final String DATEFORMAT = "dd-MM-yyyy HH:mm:ss";
static final String DATEFORMAT = "dd-MM-yyyy HH:mm:ss";
Try
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class MachineTimestamp {
static final String DATEFORMAT = "dd-MM-yyyy HH:mm:ss";
public static void main(String args[]) {
Instant machineTimestamp = Instant.now();
System.out.println("The current machine timestamp in UTC:" + machineTimestamp);
ZonedDateTime gmtDT = machineTimestamp.atZone(ZoneId.of("UTC"));
System.out.println("Current ts in GMT: " + gmtDT.format(DateTimeFormatter.ofPattern(DATEFORMAT)));
}
}
ASKER
I got wrong answer @CEHJ
The current machine timestamp in UTC:2019-10-31T06:56:24.21 8Z
Current ts in GMT: 2019-56-31 06:56:24
The current machine timestamp in UTC:2019-10-31T06:56:24.21
Current ts in GMT: 2019-56-31 06:56:24
ASKER
I want java.sql.timestamp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
Can you try this ?
Open in new window