this is my first app and i need to be using dates
i want to use an sqlite database in order to store the current date when a button is clicked
also, when that button is clicked, i want it to show the current date in a textview
now i am a PHP programmer by day, but this is all new to me. i am curious as to whether or not trying to use a unix timestamp (int) is the best solution for this, as that is what i am used to storing my dates with in PHP.
heres an example of what im working on right now in order for it to show the date after the button is clicked. the following code is in my onClick function for the button:
long currentTimestamp = System.currentTimeMillis();
Date theDate = new Date(currentTimestamp);
String showDate = theDate.getDay() + "/" + theDate.getMonth() + "/" + theDate.getYear() + " " + theDate.getHours() + ":" + theDate.getMinutes();
i starting going at this, however, in the android documentation its telling me that the functions like getDay and getMonth are deprecated and to use the Calendar functions.
now of course i dont want to start using deprecated functions since im all new to this and dont want to get into bad practices, but i read in another stack overflow question that using Calendar is slower than other solutions.
im just looking for answers as to how to go about doing this the most proper and efficient way….thank you.
EDIT:
i just read this question: How to store and get datetime value in SQLite
one of the answers recommends using a unix timestamp which is what i was originally thinking of doing. is there a way i can do this by converting a unix timestamp (long) to a string when i display it and store it, and still use the Calendar functionality?
get current time and convert it to timestamp:
convert back: