title: How to get date from room database
body: <p>I use <code>room database</code> and want to save date in database.</p>
  
  <p>I want to save date with this format <code>"dd/MM/yy"</code> to database.</p>
  
  <p>So i create <code>DateConverter</code> class to written from/into the database.</p>
  
  <p>Now i can save date with my favorite format into the database but i can't get date from database with my favorite format and when i get the date gives me all info of Date(date , time ,day).</p>
  
  <p>I can use <code>toTimestamp</code> method from <code>DateConverter</code> but i think is not good idea.</p>
  
  <p>I want to know is there a way to get date directly without using <code>DateConverter.toTimestamp</code>.</p>
  
  <pre><code>@Entity(tableName = "notes")
  public class NoteEntity {
      @PrimaryKey(autoGenerate = true)
      private int id;
      private Date date;
      private String text;
  
      @Ignore
      public NoteEntity() {
      }
  
      public NoteEntity(int id, Date date, String text) {
          this.id = id;
          this.date = date;
          this.text = text;
      }}
  
      @Ignore
      public NoteEntity(Date date, String text) {
          this.date = date;
          this.text = text;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public Date getDate() {
          return date;
      }
  
      public void setDate(Date date) {
          this.date = date;
      }
  
      public String getText() {
          return text;
      }
  
      public void setText(String text) {
          this.text = text;
      }
  </code></pre>
  
  <p><strong>DateConverter</strong></p>
  
  <pre><code>public class DateConverter {
  
     @TypeConverter
      public static Date toDate(String stringdate){
          return stringdate == null ? null : new Date(stringdate);
      }
  
      @TypeConverter
      public static String toTimestamp(Date date){
          SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yy");
          return dateTimeFormat.format(date);
      }
  }
  </code></pre>
  
  <p><strong>Dao</strong></p>
  
  <pre><code>@Dao
  public interface NoteDao {
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      void insertAll(List&lt;NoteEntity&gt; noteEntity);
  
      @Query("SELECT * FROM notes")
      List&lt;NoteEntity&gt; loadAllNotes();
  }
  </code></pre>
  
  <p><strong>Sample Data</strong></p>
  
  <pre><code>public static List&lt;NoteEntity&gt; getNotes() {
      List&lt;NoteEntity&gt; notes = new ArrayList&lt;&gt;();
      notes.add(new NoteEntity(new Date(2019,8,5), SAMPLE_TEXT_1));
      .
      .
      .
      return notes;
  }
  </code></pre>
  
  <p><strong>Main</strong></p>
  
  <pre><code>AppDatabase appDatabase = AppDatabase.getInstance(context);
  
  appDatabase.noteDao().insertAll(getNotes());
  
  List&lt;NoteEntity&gt; notesData = new ArrayList&lt;&gt;();
  notesData = appDatabase.noteDao().loadAllNotes();
          Log.i("TestOutput1", String.valueOf(notesData.get(0).getDate()));
          Log.i("TestOutput2", DateConverter.toTimestamp(notesData .get(0).getDate()));
  </code></pre>
  
  <p><strong>LogCat</strong></p>
  
  <pre><code>I/TestOutput1: Mon Aug 05 00:00:00 GMT+04:30 2019
  I/TestOutput2: 05/08/19
  </code></pre>