Change the Unix timestamp into date format

It's very interesting. Sometimes you got the result as unix timestamp from any backend apis or some results. It's simple method to convert the unix timestamp into date format.

// Unix timestamp into time format
public String getDateFormat(String dateformat) {
long dt = Long.parseLong(dateformat);
Date date = new Date(dt * 1000L); // *1000 is to convert seconds to
// milliseconds
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); // the
sdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String formattedDate = sdf.format(date);
return formattedDate;
}

Comments

Popular posts from this blog

Mastering API Development: Why Postman Reigns Supreme Over Swagger

Email Address Validation

Flutter web view