Skip to content

Instantly share code, notes, and snippets.

@tmaxxdd
Created December 19, 2020 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmaxxdd/b01deed6e129770540e6ad9004211c8b to your computer and use it in GitHub Desktop.
Save tmaxxdd/b01deed6e129770540e6ad9004211c8b to your computer and use it in GitHub Desktop.
public class SQLTypeConverters {
@TypeConverter
public Date fromTimestamp(String value) {
Date defaultDate = new Date();
SimpleDateFormat format = new SimpleDateFormat();
try {
return value.equals("") ? defaultDate : format.parse(value);
} catch (ParseException e) {
e.printStackTrace();
return defaultDate;
}
}
@TypeConverter
public String toTimestamp(Date date) {
if (date == null) {
return "";
} else {
return date.toString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment