sharang gupta sharang gupta - 1 month ago 7
Android Question

I want to get the date along with the time in my android application

I tried the code below, and although I have given DateFormat.LONG as a parameter , i only get the date and not the time.How do i get both the date and time?

Date date = new Date(System.currentTimeMillis());
Log.i("#####",DateFormat.getDateInstance(DateFormat.LONG).format(date));


heres my output : 20 October 2016

Answer

Try this.

DateFormat df = new SimpleDateFormat("yyyy/MM/dd kk:mm:ss");
Calendar c    = Calendar.getInstance();
Date day      = c.getTime();
String s2     = df.format(day);