code: @Nullable
      public static Date getDate(@NonNull SharedPreferences prefs, @NonNull String key) {
          long time = prefs.getLong(key, Long.MIN_VALUE);
          return time == Long.MIN_VALUE ? null : new Date(time);
      }
docs: Retrieves date value stored as long.