Classic ASP - format date

2019-07-25 14:43发布

问题:

I have a date being extracted from the database which is formatted as following

12/23/2005

Which is

mm/dd/yyyy

I want to convert it in classic asp to the following

December 23 2004

Could anyone help me with this?

Cheers,

回答1:

You could try this:

Function FormatDate(input)
    FormatDate = MonthName(Month(CDate(input))) & " " & Day(CDate(input)) & " " & Year(CDate(input))
End Function
Response.Write(FormatDate("12/23/2005"))

I'm assuming you want it to show "December 23 2005" if you want it to show "December 23 2004" then just subtract one from the Year() call:

FormatDate = MonthName(Month(CDate(input))) & " " & Day(CDate(input)) & " " & (Year(CDate(input))-1)


回答2:

assuming you are doing this in c#

DateTime thisDate = new DateTime.Now;
String outString = thisDate.ToString("MMMM dd, yyyy");


标签: asp-classic