Budi Darmawan Budi Darmawan - 1 year ago 80
Android Question

get current date and time

I'm kind of stuck on date and time.
I want my program to create the date like this "20121217". The first 4 letters are the year, the second 2 letters are the month and the last 2 are the day. year+month+day

The time is "112233" hour+minute+second

Thanks for your help!

Answer Source

That's a formatting issue. Java uses java.util.Date and java.text.DateFormat and java.text.SimpleDateFormat for those things.

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd hhmmss");
Date today = new Date();
String s = dateFormatter.format(today);