黑马程序员----C#占位符和格式符

 

C或c        Currency货币格式
D或d        Decimal十进制格式(十进制整数,不要和.Net的Decimal数据类型混淆了)
E或e        Exponent指数格式
F或f         Fixed point固定精度格式
G或g       General常用格式
N或n       用逗号分割千位的数字,比如1234将会被变成1,234
P或p        Percentage百分符号格式
R或r        Round-trip圆整(只用于浮点数)保证一个数字被转化成字符串以后可以再被转回成同样的数字
X或x       16进制格式

d MM/dd/yyyy
ShortDatePattern(短日期模式)

D dddd,MMMM dd,yyyy LongDatePattern(长日期模式)

F dddd,MMMM dd,yyyy HH:mm Full date and time (long date and short time)(全日期和时间模式)

F dddd,MMMM dd,yyyy HH:mm:ss FullDateTimePattern (long date and long time)(长日期和长时间)

G MM/dd/yyyy HH:mm General (short date and short time)(通用模式,短日期和短时间)

G MM/dd/yyyy HH:mm:ss General (short date and long time)(通用模式,短日期和长时间)

M,M MMMM dd MonthDayPattern(月天模式)

r,R ddd,dd MMM yyyy,HH':'mm':'ss 'GMT' RFC1123Pattern (RFC1123模式)

S yyyy-MM-dd HH:mm:ss SortableDateTimePattern (conforms to ISO 8601) using
local time(使用本地时间的可排序模式)

T HH:mm ShortTimePattern (短时间模式)

T HH:mm:ss LongTimePattern(长时间模式)

U yyyy-MM-dd HH:mm:ss UniversalSortable-DateTimePattern (conforms to ISO 8601)
using universal time(通用可排序模式)

U dddd,MMMM dd,yyyy,HH:mm:ss UniversalSortable-DateTimePattern(通用可排序模式)
y,Y MMMM,yyyy YearMonthPattern(年月模式)

实例如下:

static void Main()

{

Console.Write("{0:D}",DateTime.Now); //输出到天

Console.Write("{0:y}",DateTime.Now); //输出到月

Console.Write("{0:m}",DateTime.Now); //取出是那个月

Console.Write("{0:T}",DateTime.Now); // 取长时间到秒

Console.Write("{0:t}",DateTime.Now); //取短时间到分

Console.Write("{0:tt}",DateTime.Now); //取出是上午还是下午

}

 

posted @ 2012-10-07 19:03  再美也是伤  阅读(229)  评论(0编辑  收藏  举报