How to convert calendar date to yyyy-MM-dd HH:mm:ss format.
protected String paymentDatetime (String transmissionDateTime){
long transactionDateTime = System.currentTimeMillis();
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
SimpleDateFormat df = new SimpleDateFormat("MMddhhmmss");
Calendar nowDate = Calendar.getInstance();
nowDate.setTime(now);
Calendar transmissionDate = Calendar.getInstance();
transmissionDate.setTime(df.parse(transmissionDateTime));
transmissionDate.set(Calendar.YEAR, nowDate.get(Calendar.YEAR));
transactionDateTime = transmissionDate.getTime().getTime();
} catch (ParseException e) {
LOGGER.error("cannot parse transmission date time : " + transmissionDateTime);
}
return sdf.format(transactionDateTime);
}
I want to get the value thrown by String transmissionDateTime, but in fact when I throw the value = 1707125517 (in AM) will be convert to "2020-07-17 00:55:17". How to convert so that every 12.00 or 00.00 (12 o'clock) both AM and PM don't change?