我在android中使用图像,文本和日期实现自定义列表视图,但是当我调用getDate方法时它会工作但是返回1/1/1970而不是显示我的系统日期?
答案 0 :(得分:2)
FYI, getDate() => 不推荐使用此方法。它会返回月份的日期。
您可以使用:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // you can mention any format which you want
String currentDateandTime = sdf.format(new Date());
答案 1 :(得分:2)
您可以使用new java.util.Date()
,它将包含实际日期。您还可以使用Calendar.getInstance()
或long time = System.currentTimeMillis(); new Date(time);
答案 2 :(得分:1)
使用此:
Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND)
答案 3 :(得分:1)
here is the complete solution.where you can get the date and also access it in the form of string.
private final static String getDateTime() {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
Log.i("Log", "date is: "+df.format(new Date()));
return df.format(new Date());
}
答案 4 :(得分:1)
你可以试试这个
DateFormat date = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
Log.i("Log", "date is: "+date.format(new Date()));
date.format(new Date());
答案 5 :(得分:0)
使用它:
long dtMili = System.currentTimeMillis();
String date = new java.text.SimpleDateFormat("dd-MM-yy").format(new java.util.Date(dtMili));
答案 6 :(得分:-1)
试试这个:
Calendarview cv=findviewbyid(R.id.cv);
long selectedDateInMillis;
long current = cv.getDate();
if(current!=new Date().getTime()){
selectedDateInMillis=new Date().getTime();
}