0

i would like to set the date format of my date picker like this:

yyyy-MM-dd HH:ss:mm

I hope this is the correct format for dates in databases. if not, please tell me which format is right.

also i would like to set the hour,minute and second of selected date like 0 Example:

2015-11-30 00:00:00

For this i use this code:

long dateTime = DatePicker.getCalendarView().getDate();
Date date = new Date(dateTime);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);

Android Studio tells me, that setHours,setMinutes and setSeconds is deprecated. what is the new way to set this values?

Trombone0904
  • 4,132
  • 8
  • 51
  • 104

2 Answers2

1

Use Calendar Object instead of Date:

Calendar c = Calendar.getInstance();
c.setTimeInMillis(DatePicker.getCalendarView().getDate(););
        c.set(Calendar.HOUR,00);

like wise

Gaurav
  • 3,615
  • 2
  • 27
  • 50
0
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");

String dateString = "2015-11-30 00:00:00";
try {

        Date date = df.parse(dateString);
        df.applyPattern("yyyy-mm-dd hh:mm:ss");
        String result = df.format(date);
    }
catch (ParseException e){
                          e.printStackTrace();
                        }
Unnati Mistry
  • 156
  • 1
  • 4