如何获得Date对象在Android的“YYYY-MM-DD”格式 [英] How to get Date object in “YYYY-MM-DD” format in android
本文介绍了如何获得Date对象在Android的“YYYY-MM-DD”格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我需要比较两个日期的要求。一个日期将来自DB是字符串YYYY-MM-DD的坚定,我需要这个字符串日期与当前的日期进行比较。
这个我转换日期字符串成Date对象。
现在我需要当前的日期也是在YYYY-MM-DD的格式,它应该是Date对象,这样我可以use.compareTo()方法比较两个日期。
请帮我该怎么做?
解决方案
日期CDATE =新的日期();
。字符串FDATE =新的SimpleDateFormat(YYYY-MM-DD)格式(CDATE);
I have a requirement that I need to compare two Dates. One Date will come from DB which is String in "YYYY-DD-MM" firm and I need to compare this String Date with current Date.
for this I am converting Date String into Date object.
Now I need current Date also in "YYYY-MM-DD" format and it should be Date object so that I can use.compareTo() method compare two dates..
Please help me how to do that...
解决方案
Date cDate = new Date();
String fDate = new SimpleDateFormat("yyyy-MM-dd").format(cDate);
这篇关于如何获得Date对象在Android的“YYYY-MM-DD”格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文