将包含日期的ASP经典变量转换为另一种日期格式

时间:2013-02-04 01:31:58

标签: asp-classic

我有一个变量,其中包含格式为mm / dd / yy的日期,我想将该格式更改为dd / mm / yy

我正在尝试使用以下代码来执行此操作:

<%
d= response.write con("date")
if IsDate(d) then
document.write(CDate(d))
%>
<tr>
    <td><%=con("location")%></td>
    <td><%=con("state")%></td>
    <td><%=con("date")%></td>
</tr>

我是走错路还是有更好的方法来做这件事?

1 个答案:

答案 0 :(得分:1)

好的,你上面的代码中有一些问题:

您不能像这样使用response.write - 您可以使用它来向页面写入内容。将该行更改为:

d=con("date") & ""

我更喜欢使用经典ASP来删除空白以消除潜在的null问题。

然后将其从mm / dd / yy转换为dd / mm / yy,您可以尝试以下操作:

d = split(d,"/")
newd = d(1) & "/" & d(0) & "/" & d(2)

希望这会有所帮助,祝你好运。

相关问题