com.uwetrottmann.tmdb2.entities.TmdbDate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tmdb-java Show documentation
Show all versions of tmdb-java Show documentation
tmdb-java is a retrofit2 based wrapper around the themoviedb.org API v3.
The newest version!
package com.uwetrottmann.tmdb2.entities;
import com.uwetrottmann.tmdb2.TmdbHelper;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TmdbDate {
// can not use ThreadLocal.withInitial as it requires Java 8
private static final ThreadLocal TMDB_DATE_FORMAT = new ThreadLocal() {
@Override
public DateFormat initialValue() {
return new SimpleDateFormat(TmdbHelper.TMDB_DATE_PATTERN);
}
};
private final Date date;
public TmdbDate(Date date) {
this.date = date;
}
public TmdbDate(String date) {
Date parsedDate;
try {
parsedDate = TMDB_DATE_FORMAT.get().parse(date);
} catch (ParseException e) {
parsedDate = null;
}
this.date = parsedDate;
}
@Override
public String toString() {
return TMDB_DATE_FORMAT.get().format(date);
}
}