如何在android中找到当月的周六和周日?

时间:2016-08-27 05:38:18

标签: java datetime android-calendar

我正在尝试在我的日历中禁用星期六和星期日。要做到这一点,我必须找到它。我尝试过,但我无法得到它。我在这里发布了代码。

Aug 25, 2016 8:48:15 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.2.Final
Aug 25, 2016 8:48:15 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.2.Final
Aug 25, 2016 8:48:16 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.3.Final
Aug 25, 2016 8:48:16 PM org.jboss.remoting3.remote.RemoteConnection handleException
ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
Aug 25, 2016 8:48:16 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to "remote ip server":7273
java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
    at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
    at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:77)
    at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:155)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createIdentifiableEjbClientContext(EjbNamingContext.java:258)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.setupScopedEjbClientContextIfNeeded(EjbNamingContext.java:123)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.<init>(EjbNamingContext.java:98)
    at org.jboss.ejb.client.naming.ejb.ejbURLContextFactory.getObjectInstance(ejbURLContextFactory.java:38)
    at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:601)
    at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:550)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:345)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.illucit.ejbremote.EjbRemoteClient.createEjbProxy(EjbRemoteClient.java:149)
    at com.illucit.ejbremote.EjbRemoteClient.main(EjbRemoteClient.java:52)
Caused by: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
    at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:388)
    at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:242)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:196)
    at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:110)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at org.xnio.ChannelListeners$DelegatingChannelListener.handleEvent(ChannelListeners.java:1092)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
    at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
    at ...asynchronous invocation...(Unknown Source)
    at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:272)
    at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:388)
    at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:187)
    at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153)
    at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133)
    at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:75)
    ... 13 more

Aug 25, 2016 8:48:16 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Aug 25, 2016 8:48:16 PM org.jboss.remoting3.remote.RemoteConnection handleException
ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
Error accessing remote bean
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:dataserver_core, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@62e7f11d
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
    at com.sun.proxy.$Proxy2.getAimedJobs(Unknown Source)
    at com.illucit.ejbremote.EjbRemoteClient.main(EjbRemoteClient.java:70)

我需要获得本月的周六和周日(比如说:8月),但我得到的结果是上个月,即7月。

2 个答案:

答案 0 :(得分:4)

请改为尝试:

List<Date> disable = new ArrayList<>();

Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
int month = cal.get(Calendar.MONTH);
do {
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY)
        disable.add(cal.getTime());
    cal.add(Calendar.DAY_OF_MONTH, 1);
} while (cal.get(Calendar.MONTH) == month);

SimpleDateFormat fmt = new SimpleDateFormat("EEE M/d/yyyy");
for (Date date : disable)
    System.out.println(fmt.format(date));

输出

Sat 8/6/2016
Sun 8/7/2016
Sat 8/13/2016
Sun 8/14/2016
Sat 8/20/2016
Sun 8/21/2016
Sat 8/27/2016
Sun 8/28/2016

答案 1 :(得分:2)

public static  ArrayList<Calendar> getAllSundayDate(Calendar aCurrentDateCal, int aMaxMonth){
    //max month next month for Exp: next 2 month from this month
    ArrayList<Calendar> disableDayList = new ArrayList<>();
    Calendar cal;
    cal = aCurrentDateCal;
    for (int index = 0; index < aMaxMonth; index++) {
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        Calendar curCal = Calendar.getInstance();
        curCal.set(year, month , 1);
        int daysInMonth = curCal.getActualMaximum(Calendar.DAY_OF_MONTH);

        for (int day = 1; day <= daysInMonth; day++) {
            curCal.set(year, month, day);
            int dayOfWeek = curCal.get(Calendar.DAY_OF_WEEK);
            if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
                disableDayList.add(curCal);
                Date curDate = new Date(curCal.getTimeInMillis());
                System.out.println(curDate);
            }
        }

        cal.add(Calendar.MONTH, 1);
    }
    return disableDayList;
}