I have recently started learning java for creating android apps. I have spent hours and hours looking for the right code to be able to use the current time and date as an int. I’m sure it’s very easy but I can’t seem to find the correct coding. My first app im creating it will be crucial for a number to increase with time. Thank you for your help!
Chris
You can use it as a
long, see javadocs:But why would you do it, that’s another question… Choose wisely 🙂 Nothing wrong with having dates represented as numbers per se, but any calculations are bound to hit some of the numerous corner cases – you might want to look at this SOq for one really mind-boggling examples:
and this SOq for a bunch of best practices:
If you are interested in any date calculations, you may want to look at Joda Time library:
I’d say that when you have such good and well tested libraries readily available, it’s rarely a good idea to go your own way.