I write two functions to get the start time and end time. The end time is always the current time and the start time is always the current time minus 2 seconds.
Here is the function code.
private fun getStartDateTime(): String {
val dateFormat = SimpleDateFormat(Constants.SERVER_DATE_FORMAT, Locale.getDefault())
val calendar = Calendar.getInstance()
calendar.add(Calendar.SECOND, -2)
return dateFormat.format(calendar.time)
}
private fun getEndDateTime(): String {
val dateFormat = SimpleDateFormat(Constants.SERVER_DATE_FORMAT, Locale.getDefault())
val date = Date()
return dateFormat.format(date)
}
In most of the devices, it's working as aspected but when I test this in Oneplus 6 it starts giving me the same time when I call this function. Please see the below screenshot of the local database table.

Question:
Those functions are called on every 2 seconds. So the start time and end time should be unique. Is there any reason why I'm not getting a unique start time and end time?
Edit
Those functions are called while creating a new object of the call like
val abc = ABC(xxx, xxx, xxx, getStartDateTime(), getEndDateTime())