To get the current date and time in Android, you can use:
Calendar c = Calendar.getInstance();
System.out.println("Current time => "+c.getTime());
Conclusion:
Current time => Thu Nov 03 15:00:45 GMT + 05: 30 2011
FYI, if you have this time in the 'c' object, you can use the SimpleDateFormat class to get the date / time in the desired format.
Final decision:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Sring formattedDate = df.format(c.getTime());
System.out.println("========> formatted date => "+formattedDate);
Conclusion:
========> formatted date => 2011-11-03 15:13:37
source
share