I need to create the following data structure:
userid, onlinetime, offlinetime
I need the user id to be repeated in the list.
Something like this:
userid: 1, onlinetime: 11:10:30, offlinetime: 11:18:12
userid: 1, onlinetime: 11:14:14, offlinetime: 11:52:41
userid: 2, onlinetime: 8:08:14, offlinetime: 1:15:00
How can I create this object, or a list?
How can I read this object or list? (I need to compare on-line and off-line time.)
You can create User objects with userId and connectionTimes properties and add them to an array of Users like this:
Once you have an array of users, you can iterate through it and find a user by comparing the userId property:
EDIT
Here’s a decomposed version of the code, based on a createUser and getConnectionTime function: