在Android的应用程序中使用日期函数? [英] Using date functions in android application?

查看:133
本文介绍了在Android的应用程序中使用日期函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示基于各国事件并在一个星期的事件列表的一些事件的数据。目前,我展示的所有事件中从文件列表形式,作为该文件包含过时事件以及但是我想显示今天的日期事件的基础上,再经过上周一周的活动上。总之我想限制在此基础上的列表中,并提取信息。我知道有一类的java.util 包含日期类,但需要一些快速的想法,并帮助我该怎么办这个?任何人都可以举出例子吗?

感谢


解决方案

  //获得一个实例
日历CAL = Calendar.getInstance();//初始化的开始或当前日期
今天的日期= cal.getTime();//找到周开始日期
INT一周中的某天= cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DATE,星期* -1);
日期startWeek = cal.getTime();//比较,如果从文件中的日期在当前周
如果(today.compareTo(FILEDATE)下; = 0&放大器;&放大器; startWeek.compareTo(FILEDATE)GT; = 0)

然后你就可以得到最终并通过这样做增加-1,-7到当前startWeek

开始下一周连续日期

或者你也可以尝试这种方式。

  //获得一个实例
日历CAL = Calendar.getInstance();//从文件中设置日期
cal.setTime(FILEDATE);//今年发现周
INT WEEKOFYEAR = cal.get(Calendar.WEEK_OF_YEAR))

根据列表或数组用于显示其分配

要格式化日期

 字符串strFileDate =20100316T0305;
日期格式格式化=新的SimpleDateFormat(YYYYMMDDThhmm);
日期FILEDATE =(日期)formatter.parse(strFileDate);

I am displaying some event data based on the todays event and a list of events in a week. Currently I am displaying all the events in form of list from the file, As the file contains out dated events as well but I want to display on the basis of today's date events and a week events then week after. In short I want to restrict the list on the basis of this and extract information. I know there is a class java.util containing Date class, but need some quick idea and help how can I do this? Can anyone quote example?

Thanks

解决方案

//get an instance
Calendar cal = Calendar.getInstance();

//initialise the start or current date
Date today = cal.getTime();

//find the week start date
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DATE, dayofweek*-1);
Date startWeek = cal.getTime();

//compare if the date from file falls in the current week
if (today.compareTo(fileDate)<=0 && startWeek.compareTo(fileDate)>=0) 

Then you can get the end and start dates of the next consecutive week by doing adding -1 and -7 to the current startWeek

OR you can also try this way

//get an instance
Calendar cal = Calendar.getInstance();

//set date from file
cal.setTime(fileDate);

//find week of year
int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR))

assign it according to List or Array for display

To format date

String strFileDate = "20100316T0305";
DateFormat formatter = new SimpleDateFormat("YYYYMMDDThhmm");
Date fileDate = (Date)formatter.parse(strFileDate); 

这篇关于在Android的应用程序中使用日期函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆