My epoch value is 3 days ahead of the actual time passed as input.
I have a date 2023-03-21T04:34:12.234567800Z in which 00Z is the offset, but once I convert it to epoch in java, I am getting an epoch output which is 3 days ahead of the time in the actual date given above? Any idea on how we can form date format for Dates having offset 00Z. I am using this format ->"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
This is the code snippet I have worked upon
public class date_to_epoch {
public static void main(String[] args) {
//The date format against which the Date will be matched
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS");
//Timezone
df.setTimeZone(TimeZone.getTimeZone("(UTC+05:30) Asia/Kolkata"));
try {
@SuppressWarnings("unused")
String rtValue="2023-03-21T04:34:12.234567800Z";
Date date = df.parse("2023-03-21T04:34:12.234567800Z");
SimpleDateFormat utcformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS");
utcformat.setTimeZone(TimeZone.getTimeZone("UTC"));
rtValue = utcformat.format(date);
long epoch = date.getTime(); // timestamp value received in rt field of log to epoch
String sDatetime = String.valueOf(epoch);
System.out.println(sDatetime);
} catch (Exception ex) {
}
}
}
1679607819800--> This was the epoch I am getting, which corresponds to a date three days ahead, So I am not able deduce the Date format for in this. enter image description here