如何在Android中获取当前系统日期?

时间:2013-08-21 13:05:23

标签: java android date datetime datepicker

我将以2013年12月28日的格式获取日期,但我需要字符串格式的当前日期,

  

8月21日星期四

这样我就可以设置TextView,

解释一下,如果您认为有必要,我是Android开发的新手。

3 个答案:

答案 0 :(得分:1)

您始终可以参考文档。 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对象的一周的格里历日历。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

目前我没有编写任何Android应用程序,我将来会这样做。但我在这里发现了。它可能会使你的问题充满希望。

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)));
 }

在America / Los_Angeles时区的en_US设备上运行时生成此输出:

 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
相关问题