2

下面的代码输出当月的周末日期。

代码:

<cfparam name="month" default="#DatePart('m', Now())#">
<cfparam name="year" default="#DatePart('yyyy', Now())#">

<cfset ThisMonthYear=CreateDate(year, month, '1')>
<cfset Days=DaysInMonth(ThisMonthYear)>

<cfset ThisDay = 1>
<cfloop condition="ThisDay LTE Days">
    <cfset presentDay = CreateDate(year, month, thisday)>
    <cfif DayOfWeek(presentDay) EQ '7'>
        <cfoutput>#ThisDay#</cfoutput>
    <cfelseif DayOfWeek(presentDay) EQ '1'>
        <cfoutput>#ThisDay#</cfoutput>
    </cfif>
    <cfset ThisDay = ThisDay + 1>
</cfloop>

输出:
6 7 13 14 20 21 27 28

我正在尝试将这个 cfloop 的值传递到一个变量中。下面的代码仅显示最后一个周末的日期值。

代码:

<cfset ThisDay = 1>
<cfset weekDayOfMonth = "">
<cfloop condition="ThisDay LTE Days">
    <cfset presentDay = CreateDate(year, month, thisday)>
    <cfif DayOfWeek(presentDay) EQ '7'>
        <cfset weekDayOfMonth = ThisDay>
    <cfelseif DayOfWeek(presentDay) EQ '1'>
        <cfset weekDayOfMonth = ThisDay>
    </cfif>
    <cfset ThisDay = ThisDay + 1>
</cfloop>
<cfoutput>#weekDayOfMonth#</cfoutput>

输出
28

问题,我需要在我的最后一个 cfloop 代码中修复什么,以便我可以将循环值传递给jsWeekendDates变量?

任何帮助将不胜感激。
谢谢你。

4

1 回答 1

2

只是自己想出来的。享受。

<cfset ThisDay = 1>
<cfset weekDay = "">
<cfloop condition='ThisDay LTE Days'>
    <cfset presentDay = CreateDate(year, month, thisday)>
    <cfif DayOfWeek(presentDay) EQ '1' OR DayOfWeek(presentDay) EQ '7'>
        <cfset weekDay = weekDay & " " & ThisDay">
    </cfif>
    <cfset ThisDay = ThisDay + 1>
</cfloop>
<cfoutput>#weekDay#</cfoutput>
于 2013-04-18T21:17:53.043 回答