简体   繁体   中英

how can i get current system date in Android?

I am getting date in 28/12/2013 format, but I need current date in a String format,

like

Thursday, August 21

so that I can set over TextView,

Explain a bit, if you think something is necessary, I am new to Android Development.

You can always refer to the documentation. http://developer.android.com/reference/java/util/Date.html

In the documentation you will find this:

Calendar.get(Calendar.MONTH)
public int getMonth ()   #old do not use

Returns the gregorian calendar month for this Date object.

Calendar.get(Calendar.YEAR
public int getYear ()   #old do not use

Returns the gregorian calendar year since 1900 for this Date object.

Calendar.get(Calendar.DAY_OF_WEEK)
public int getDay ()    #old do not use

Returns the gregorian calendar day of the week for this Date object.

SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMM dd");
String formatedDate = sdf.format(your_date);

At the moment I haven't programmed any android app, I'll do that in the future. But I have found that here. It may soulve your problem hopefully.

DateFormat[] formats = new DateFormat[] {
   DateFormat.getDateInstance(),
   DateFormat.getDateTimeInstance(),
   DateFormat.getTimeInstance(),
 };
 for (DateFormat df : formats) {
   System.out.println(df.format(new Date(0)));
   df.setTimeZone(TimeZone.getTimeZone("UTC"));
   System.out.println(df.format(new Date(0)));
 }

Produces this output when run on an en_US device in the America/Los_Angeles time zone:

 Dec 31, 1969
 Jan 1, 1970
 Dec 31, 1969 4:00:00 PM
 Jan 1, 1970 12:00:00 AM
 4:00:00 PM
 12:00:00 AM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM