我在android中使用图像,文本和日期实现自定义列表视图,但是当我调用getDate方法时它将工作,但返回1/1/1970而不是显示我的系统日期?getDate()不返回系统具有的确切日期?
回答
你可以使用new java.util.Date()
,它将包含实际的日期。您还可以使用Calendar.getInstance()
或long time = System.currentTimeMillis(); new Date(time);
谢谢它的工作 – aadi 2012-07-25 08:09:58
你受欢迎的! – 2012-07-25 08:14:34
使用这样的:
long dtMili = System.currentTimeMillis();
String date = new java.text.SimpleDateFormat("dd-MM-yy").format(new java.util.Date(dtMili));
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());
使用此:
Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND)
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());
}
你可以试试这个
DateFormat date = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
Log.i("Log", "date is: "+date.format(new Date()));
date.format(new Date());
试试这个:
Calendarview cv=findviewbyid(R.id.cv);
long selectedDateInMillis;
long current = cv.getDate();
if(current!=new Date().getTime()){
selectedDateInMillis=new Date().getTime();
}
这不提供问题的答案。一旦你有足够的[声誉](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-can- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17318756) – Jerodev 2017-09-13 11:31:50
此解决方案适用于万一您希望日期和时间以毫秒为单位的calendarview和caledarview给出错误日期 – Alpha 2017-09-14 09:09:01
- 1. Android getDate返回错误的日期
- 2. SQL GetDate()显示当前日期或系统日期?
- 3. jQuery UI Datepicker getDate在无效日期返回当天日期
- 4. twitter引导datetimepicker不返回正确的UTC日期时间通过getDate函数
- 5. SqlDatareader GetValue根据系统日期格式返回日期值
- 6. jquery ui datepicker getDate返回对象而不是日期
- 7. 的SimpleDateFormat返回不正确的日期
- 8. NSDateFormatter没有返回正确的日期
- 9. LocalDate.toDate()返回不准确的日期
- 10. UIDatePicker&NSDateFormatter返回不正确的日期
- 11. CalendarView getDate()不返回时间
- 12. 为什么GetDate()返回明天的日期?
- 13. SQL服务器GETDATE函数返回一个将来的日期
- 14. PHP,日期()不返回正确的日期/时间
- 15. 返回不同的日期
- 16. 为什么在系统日期返回0?
- 17. 返回系统日期复选框检查jquery
- 18. Rails 2.3.2,错误日期,系统日期正确
- 19. PHP getdate没有返回正确的时间?
- 20. javascript日期()对象返回有效但不新的日期()
- 21. <f:convertDateTime>不显示正确的系统日期和时间
- 22. 阵列日期回报的对象系统日期时间不是数组
- 23. HttpServletRequest的getRequestURL()不返回确切的URL
- 24. 为什么getdate(1500000000)返回2017年7月7日,而getdate(2500000000)返回2月13日1913
- 25. Java的返回码不正确记录与C++系统()调用
- 26. 作为字符而不是日期的系统日期
- 27. Javascript方法Date()在我的系统上返回错误的日期(2月9日,而不是9月2日),
- 28. Laravel Eloquent ORM急切加载。关系不正确地返回空
- 29. PHP和系统日期不同
- 30. getdate()返回错误时间
这个问题意味着时间到了'0'(1970年1月1日距离Unix Epoch 0ms)。你能显示一些代码吗?你如何填充列表,以及如何获取日期? – Eric 2012-07-25 07:03:17
返回“1970年1月1日”是*不能*很好地总结为“不返回确切的日期”..(也就是说,有些东西只是错误的,它可能不是API /运行时。) – 2012-07-25 07:07:40