2012-07-25 63 views
0

我在android中使用图像,文本和日期实现自定义列表视图,但是当我调用getDate方法时它将工作,但返回1/1/1970而不是显示我的系统日期?getDate()不返回系统具有的确切日期?

+1

这个问题意味着时间到了'0'(1970年1月1日距离Unix Epoch 0ms)。你能显示一些代码吗?你如何填充列表,以及如何获取日期? – Eric 2012-07-25 07:03:17

+0

返回“1970年1月1日”是*不能*很好地总结为“不返回确切的日期”..(也就是说,有些东西只是错误的,它可能不是API /运行时。) – 2012-07-25 07:07:40

回答

2

你可以使用new java.util.Date(),它将包含实际的日期。您还可以使用Calendar.getInstance()long time = System.currentTimeMillis(); new Date(time);

+0

谢谢它的工作 – aadi 2012-07-25 08:09:58

+0

你受欢迎的! – 2012-07-25 08:14:34

0

使用这样的:

long dtMili = System.currentTimeMillis(); 

String date = new java.text.SimpleDateFormat("dd-MM-yy").format(new java.util.Date(dtMili)); 
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
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()); 
    } 
1

你可以试试这个

DateFormat date = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss"); 
    Log.i("Log", "date is: "+date.format(new Date())); 
    date.format(new Date()); 
-1

试试这个:

Calendarview cv=findviewbyid(R.id.cv); 
long selectedDateInMillis; 
long current = cv.getDate(); 
if(current!=new Date().getTime()){ 
    selectedDateInMillis=new Date().getTime(); 
} 
+0

这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17318756) – Jerodev 2017-09-13 11:31:50

+0

此解决方案适用于万一您希望日期和时间以毫秒为单位的calendarview和caledarview给出错误日期 – Alpha 2017-09-14 09:09:01

相关问题