I need to add a new feature in my android app. I need a serial number with a specific pattern every time when a user logged in. The pattern is:
[date]_1.....[date]_n
for example, today is 21-09-2021. so first serial number will be 210921_1, the next one will be 210921_2. Tomorrow the first serial number will be 220921_1, the next one 220921_2. Like this it will continue. How can I do it? please forgive if I make any mistake.
CodePudding user response:
The first step with solving a problem such as this is to break it down into the separate logic elements.
- Extract Date Today.
- Check 'number' of previous dates stored.
- Convert data to DDMMYY format.
- Append _
- Append 'number' 1
- Increment 'number' counter.
Those are the steps. You therefore need a variable to start with that will contain the current value of the number of serials stored that day, this will start at 0.
Next you now need to understand how to get the 'date' and how to format it. Look at the APIs for Calendar and SimpleDateFormat.
That's about it.
I could post code but, there's a lot of examples for those and, really, with that logic, you should now be able to do this yourself.
Good luck!