English 中文(简体)
在充满日期的矢量中删除周末
原标题:Removing weekends in a vector filled with Dates
  • 时间:2011-05-31 15:07:13
  •  标签:
  • java

I have a vector that is created by retrieving data from a database It is filled with information that includes Date, Time, Volume ect... I need to create a spreadsheet from these values however I need to Remove values where the date is on a weekend(and specific holidays if possible) but more importantly the weekends If anyone knows of a function that is able to do this that would be great Thanks.

最佳回答

如果您在Java中有一个Date对象,那么您可以使用日历对象执行此操作。

获取日历的一个实例,然后调用Get(Calendar.DAY_of_WEEK)。如果值为Saturday或Sunday,请将其从集合中删除。

Calendar calendar = Calendar.getInstance();
calendar.setTime(yourDateObject);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if(dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
    //remove this Date
}
问题回答

如果您有日期的时间戳,则可以使用GregorianCalendar。

http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html#setFirstDayOfWeek(int

GregorianCalendar cal = new GregorianCalendar();
cal.setTime(yourDate);
cal.get(Calendar.DAY_OF_WEEK) // Would be Calendar.SUNDAY or something;




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签