Sometimes we have to change the time to achieve different display effects.
The default format is: 2005-6-6 14:33:34
What if you want to change into a 200506,06-2005,2005-6-6 or more?
We need to use: DateTime.ToString method (String, IFormatProvider)
Using System;
Using System.Globalization;
String format= "D";
DateTime Date=datatime,now;
Response.Write (date. ToString (format, datetimeformatinfo.invariantinfo));
Result output
Thursday, June 16, 2005
Parameter format format verbose usage
Format Character Association attribute/description
D ShortDatePattern
D Longdatepattern
F Full Date and time (long date and short time)
F Fulldatetimepattern (long date and long time)
G General (short date and short time)
G General (short date and long time)
M, M Monthdaypattern
R, R Rfc1123pattern
s use local time Sortabledatetimepattern (based on ISO 8601)
T Shorttimepattern
T Longtimepattern
U universalsortabledatetimepattern format for displaying Universal Time
U use the full date and time of the universal Time (long date and long time)
Y, y Yearmonthpattern