【发布时间】:2011-07-02 16:12:02
【问题描述】:
如何在不使用Calender.getInstance()的情况下获取当前系统的时间和日期?
【问题讨论】:
如何在不使用Calender.getInstance()的情况下获取当前系统的时间和日期?
【问题讨论】:
试试这个:
//-------- Don't know whether this will work on android or not.
long dtMili = System.currentTimeMillis();
Date dt = new Date(dtMili);
或
new Date().getTime()
【讨论】:
DateFormat 类。
构造一个新的Date 将给出当前日期。此后您可以使用 date.setTime(System.currentTimeMillis()) 来更新该对象
【讨论】:
试试
Date d = new Date();
CharSequence s = DateFormat.format("EEEE, MMMM d, yyyy ", d.getTime());
您可以根据需要编辑格式字符串..
【讨论】:
The method format(Date) in the type DateFormat is not applicable for the arguments (String, long)
你可以试试这个:
DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("GMT+05:30"));
df.format(new Date(System.currentTimeMillis());
【讨论】: