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

Flutter Bloc - Clean Architecture

Dependencies vs Dev Dependencies in Flutter

What's new in android 14?