弄乱字符串并不难,但是由于您正在处理日期,所以让我们使用日期函数。
如果你有一个字符串,最好的办法是把它转换成一个日期对象,使用
<cfset myDate = ParseDateTime(string)>
一旦它是一个日期对象,你就可以用它做任何你想做的事情。根据需要使用 Dateformat 对其进行操作。
<cfoutput>#dateformat(myDate, "mmm dd, yyyy")#</cfoutput>
ParseDateTime documentation here
DateFormat documentation here
编辑 - 改为使用字符串。
您可以使用 LEFT 来获取字符串的左边部分。要知道您想要多少个字符,您需要找到第二个“,”逗号的位置。假设格式一致,第一个逗号应该不超过 8 个字符,所以我们使用 FIND 在字符串中查找“,”,从位置 8 开始。
<cfset theLoc = find(",", album[currentrow]['date'], 8) >
然后我们使用left函数来获取字符,但是我们不想要逗号,所以我们把它去掉1。
<cfset theDate = left( album[currentrow]['date'], theLoc- 1 )>
<cfoutput>#theDate#</cfoutput>
你可以内联,但是有点麻烦
<cfset theDate = left( album[currentrow]['date'], find(",", album[currentrow]['date'], 8)- 1 )>