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.
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.
您可以随时参考文档。 http://developer.android.com/reference/java/util/Date.html
在文档中,您会发现:
Calendar.get(Calendar.MONTH)
public int getMonth () #old do not use
返回此 Date 对象的公历月份。
Calendar.get(Calendar.YEAR
public int getYear () #old do not use
返回此 Date 对象自 1900 年以来的公历年。
Calendar.get(Calendar.DAY_OF_WEEK)
public int getDay () #old do not use
返回此 Date 对象的公历星期几。
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMM dd");
String formatedDate = sdf.format(your_date);
目前我还没有编写任何安卓应用程序,我会在未来这样做。但我在这里找到了。希望它可以解决您的问题。
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)));
}
en_US
在 America/Los_Angeles 时区的设备上运行时产生此输出:
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