Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get timestamp along with timezone in java

gopi krishna kasireddyMay 4 2023 — edited May 4 2023

Hello,

How to get a timestamp with timezone in java.

import java.util.Date;

import java.util.TimeZone;

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
String dateValue = "Wed May 29 10:00:00 CDT 2023";

TimeZone tz = TimeZone.getTimeZone("America/Chicago");
TimeZone.setDefault(tz);
System.out.println("TIMESTAMP"+new java.sql.Timestamp(sdf.parse(dateValue).getTime())) is

TIMESTAMP 2023-05-29 10:00:00.0

Comments
Post Details
Added on May 4 2023
3 comments
4,180 views