0

In my case just display current time in textview but it not working properly.

Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime();

dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
String todayAsString = dateFormatter.format(today);
datePickUp.setText(todayAsString);

SimpleDateFormat dF = new SimpleDateFormat("hh:mm a");
String currentTime = dF.format(today);
timePick.setText(currentTime);

In today the value is Wed Jun 21 12:22:32 GMT+05:30 2017 but in currenTime value is as 06:52 AM.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

you can also use android text time format

import java.util.Calendar
Calendar c = Calendar.getInstance(); 
int seconds = c.get(Calendar.SECOND);

or those who might rather prefer a customized format, you can use:

DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, HH:mm");
String date = df.format(Calendar.getInstance().getTime());
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Saurabh
  • 774
  • 5
  • 15