webForumDet fria alternativet

Datumformatering

ASP

1 svar · 1 101 visningar · startad av Erik Juhlin

Medlem sedan maj 200010 687 inlägg
Frågan#1

Ett försök till att göra datumformatering lite enklare. Har härmat Format funktionen i VB. :)

<%
Function Format(dDate, sFormat)
	dDate = CDate(dDate)
	sFormat = Replace(sFormat, "YYYY", Right("0000" & Year(dDate), 4), 1, -1, 1)
	sFormat = Replace(sFormat, "MM", Right("00" & Month(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "M", Month(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "DD", Right("00" & Day(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "D", Day(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "HH", Right("00" & Hour(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "H", Hour(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "NN", Right("00" & Minute(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "N", Minute(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "SS", Right("00" & Second(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "S", Second(dDate), 1, -1, 1)
	Format = sFormat
End Function

Response.Write Format(Now, "YYYY-MM-DD HH:NN:SS.000") & "<br>"
Response.Write Format(Now, "H:NN - D / M, YYYY") & "<br>"
Response.Write Format(Now, "Kl. HH:NN:SS") & "<br>"
%>
Medlem sedan dec. 19998 577 inlägg
#2

Har gjort en liknande funktion: http://www.webeye.nu/default2.asp?que=asp/format.asp

Dock är det ganska mycket mer kod, men innehåller lite fler "funktioner". ;)

Mvh, Vide

256 ms totalt · 4 externa anrop · v20260731065814-full.86ec41c2
134 ms — deklarationer (db)
0 ms — hämta statistik (cache)
119 ms — hämta tråd, inlägg och bilagor (db)
134 ms — ändringar (db)