在Android的应用程序中使用日期函数?应用程序、函数、日期、Android

2023-09-07 13:19:47 作者:駃樂dē眼涙

我显示基于各国事件并在一个星期的事件列表的一些事件的数据。目前,我展示的所有事件中从文件列表形式,作为该文件包含过时事件以及但是我想显示今天的日期事件的基础上,再经过上周一周的活动上。总之我想限制在此基础上的列表中,并提取信息。我知道有一类的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)) 

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

屏幕使用时间手机版下载 安卓管理屏幕使用时间app下载v1.1.0131 安卓版 安粉丝手游网

要格式化日期

 字符串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);