2

My question is,

What is the best way to store date/time in an SQL database on android so that the date and time can later be used for sorting the items that are getting added to the list?

Stagleton
  • 21
  • 3
  • I'd use UNIX TIMESTAMP (int). See http://stackoverflow.com/questions/732034/getting-unixtime-in-java – Alxandr Sep 03 '11 at 10:28

2 Answers2

3

To easily get and store timestamp, you can use:

    long time = System.currentTimeMillis();

"It is the standard 'wall' clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network" See more here: Android Developers

StarsSky
  • 6,721
  • 6
  • 38
  • 63
peter.bartos
  • 11,855
  • 3
  • 51
  • 62
0
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); 
Date mDate = new Date();

insert in database will be dateFormat.format(mDate)

Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115