I have a requirement to fetch a UNIX timestamp (String), convert it into a date in a specific format, and store it in a MySQL DB in a DATETIME Column.
Here is my piece of code (simplified):
String ep ="a1527069600";
Long epoch = Long.parseLong(ep.substring(1, ep.length()));
Date dt = new Date(epoch*1000L);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
a");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
System.out.println("SDF.Format - "+sdf.format(dt));
System.out.println("SDF.parse - "+sdf.parse(sdf.format(dt)));
Console output:
SDF.Format - 23/05/2018 03:30:00 PM <br>
SDF.parse - Wed May 23 15:30:00 IST 2018
When I try to push this value in a MySQL DB, it throws Invalid DateError.
Just confused why sdf.format
and sdf.parse
shows timestamp in different formats.