简体   繁体   中英

How to convert the timestamp date format to dd/mm/yyyy?

I want to convert this timestamp format 2021-04-21T17:00:50 to "dd/MM/YYYY"

I'm getting number format exception :

public static final String DATE_FORMAT = "dd-MMM-yyyy";
private String courseStartDate = null;
long longDate = 2021-04-21T17:00:50; 

courseStartDate = getDateTimeFromTimeStamp(longDate, DATE_FORMAT);

public String getDateTimeFromTimeStamp(Long time, String mDateFormat) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(mDateFormat);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date dateTime = new Date(time);
    return dateFormat.format(dateTime);
}
LocalDateTime
.parse( "2021-04-21T17:00:50" )
.format(
    DateTimeFormatter.ofPattern( "dd/MM/uuuu" )
)

This has been covered many many times. So search to learn more .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM