我想更改DayOfWeek()
功能,以便我可以根据自己想要的一周的第一天获取日期。所以我在这段代码中所做的是我正在设置 a startDate
,endDate
并且selectDays
我想检查它。这是我的代码:
<cfscript>
function Mydayofweek(date, day_1)
{
return (((DayOfWeek(date) + (7 -day_1)) MOD 7) +1);
}
</cfscript>
<cfset startDate = '07/01/2013'>
<cfset endDate = '07/25/2013'>
<Cfset mydates = ''>
<cfset selectDays = '2,6'>
<cfset MyWeekFirstDay = 6> <!---I selected Friday = 6 --->
<cfset new = ''>
<cfoutput>
<cfloop list="#selectDays#" delimiters="," index="d">
<cfset new &= '#Mydayofweek(d, MyWeekFirstDay)#,' >
</cfloop>
<cfif new NEQ ''>
<cfset ScheduleDate = left(new, (len(new)-1) )>
</cfif>
<cfdump var="#ScheduleDate#"><br />
</cfoutput>
<cfset AppendToMyDates = false>
<cfloop from="#startDate#" to="#endDate#" index="day">
<cfif AppendToMyDates is false and DayOfWeek(day) is ListFirst(selectDays)>
<cfset AppendToMyDates = true>
</cfif>
<cfif listfind(ScheduleDate, DayOfWeek(day), ',') NEQ 0 and AppendToMyDates is true>
<cfset mydates &= "#dateformat(day, 'mmm, dd, yyyy dddd')#,<br />">
</cfif>
</cfloop><cfoutput>#mydates#</cfoutput>
这是用 ColdFusion 编写的。该代码生成以下输出:
4,1
Jul, 03, 2013 Wednesday,
Jul, 07, 2013 Sunday,
Jul, 10, 2013 Wednesday,
Jul, 14, 2013 Sunday,
Jul, 17, 2013 Wednesday,
Jul, 21, 2013 Sunday,
Jul, 24, 2013 Wednesday,
输出应该是这样的,因为我选择 Friday = 1 到 Thursday = 7 所以上面的日子selectDays = '2,6'
现在应该指向 selectDays = '7,4' 相对于我的第一天2,6
7,4
Jul, 06, 2013 Saturday,
Jul, 10, 2013 Wednesday,
Jul, 13, 2013 Saturday,
Jul, 17, 2013 Wednesday,
Jul, 20, 2013 Saturday,
Jul, 24, 2013 Wednesday,
我已经设置了我的selectDays = '2,6'
意思是我想要获取日期,Saturday
因为Wednesday
我已经将 6 设置为我一周的第一天,它从星期五开始(默认情况下是星期天)。我的日子从星期日开始Sunday = 1 , Monday = 2 , Tuesday = 3 , Wednesday = 4 , Thursday = 5 , Friday = 6 , Saturday = 7
,现在我从Friday = 1 , Saturday = 2 ,Sunday = 3 , Monday = 4 , Tuesday = 5 , Wednesday = 6 , Thursday = 7
脚本函数中更改了日期。实际上,我认为我的脚本函数中存在我不理解的错误。请帮我找出问题并解决,谢谢