I just want to ask, is there a way to exclude the date in Timestamp from Firestore? Like, I only want the hour and minutes to be displayed.
For example, the output of my code below is “Date: Tue Aug 24 23:59:00 GMT+08:00 2021”
holder.binding.tvTimeIn.setText(employeeModel.getTime_in().toDate().toString());
And I only want the “23:59:00” part to be displayed.
Advertisement
Answer
What you are storing in the database is a Firestore Timestamp object that represents a point in time with nanoseconds precision. If you want to display only the time, then you have to format it like this:
Date date = employeeModel.getTime_in().toDate() SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); String time = sdf.format(date); holder.binding.tvTimeIn.setText(time);
Alternatively, you can store in the database only the time in a String format, if this is your requirement.