How to get the current date on Android? [closed]

1

I'm developing an application and I need to get the current date only, I used Date data = new Date(); only that it does not work. I tried localdatetime also more was not, does anyone have any suggestions?

    
asked by anonymous 21.09.2017 / 04:32

1 answer

8

Do the following, import SimpleDateFormat

import java.text.SimpleDateFormat;

Create an instance of the class, passing the date format

SimpleDateFormat formataData = new SimpleDateFormat("dd-MM-yyyy");

Create an instance of class Date

Date data = new Date();

Format the date

String dataFormatada = formataData.format(data);

Exit

System.out.println("Data formatada " + dataFormatada );
// Data formatada 21-09-2017

See working at ideone

    
21.09.2017 / 04:52