If we make a calendar app, we
need to get date time in user phone.
Use this command, import
java.util.Date
String p=new
Date().toString();
Split string to get date, year
and month
String a[] = p.split(" ");
int n = a.length;
String year = a[n - 1];
String month = a[1];
String day = a[2];
tv.setText("Year:
"+year+"\n"+"Month:
"+month+"\n"+"Day:
"+day+"");
This way doesn’t change result
if user change phone language setting.
If we use SimpleDateFormat, when
user change phone language, the order of day, month, year change too.
No comments:
Post a Comment