I get response from an News API detailing the time an article was published as a UTC string ex below:
"2020-07-17T19:30:40Z"
The goal is to have the articles say when they were published in hours ago for example, a news article could say that it was published 5 hours ago. I created function to convert the time string to a locale time format, although it doesn't work as intended at all. Below is the function:
public static String convertUtc2Local(String utcTime) {
String convertedTime = utcTime;
String pattern = "MMMM d, yyyy";
Locale locale = Locale.getDefault();
/*TODO Fix this it just shows todays date not the actual date string*/
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
convertedTime = simpleDateFormat.format(date);
return convertedTime;
}
How do I convert the UTC time string to hours ago?