Manikandan Manikandan - 1 year ago 72
Android Question

How to get the current time in android

I want to get the current time in Android. It should be displayed like 2:30pm and I want to store it in a database. I searched a lot. But I don't know how to do it. How can I achieve this?

Answer Source
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
Date currentLocalTime = cal.getTime();
DateFormat date = new SimpleDateFormat("HH:mm a"); 
// you can get seconds by adding  "...:ss" to it

String localTime = date.format(currentLocalTime); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download