c 中ToString格式大全

2021-09-30 04:26:00 字數 3589 閱讀 3877

字元型轉換為字串

// c 貨幣

2.5.tostring("c"); // ¥2.50

// d 10進製數

25.tostring("d5"); // 25000

// e 科學型

25000.tostring("e"); // 2.500000e+005

// f 固定點

25.tostring("f2"); // 25.00 "f?"表示保持幾位小數

// g 常規

2.5.tostring("g"); // 2.5

// n 數字

2500000.tostring("n"); // 2,500,000.00

// x 16進製制

255.tostring("x"); // ff

// c# 日期格式

datetime dt = datetime.now;

dt.tostring();//2005-11-5 13:21:25

dt.tofiletime().tostring();//127756416859912816

dt.tofiletimeutc().tostring();//127756704859912816

dt.tolocaltime().tostring();//2005-11-5 21:21:25

dt.tolongdatestring().tostring();//2023年11月5日

dt.tolongtimestring().tostring();//13:21:25

dt.tooadate().tostring();

dt.toshortdatestring().tostring();//2005-11-5

dt.toshorttimestring().tostring();//13:21

dt.touniversaltime().tostring();//2005-11-5 5:21:25

dt.year.tostring();//2005

dt.date.tostring();//2005-11-5 0:00:00

dt.dayofweek.tostring();//saturday

dt.dayofyear.tostring();//309

dt.hour.tostring();//13

dt.millisecond.tostring();//441

dt.minute.tostring();//30

dt.month.tostring();//11

dt.second.tostring();//28

dt.ticks.tostring();//632667942284412864

dt.timeofday.tostring();

dt.tostring();//2005-11-5 13:47:04

dt.addyears(1).tostring();//2006-11-5 13:47:04

dt.adddays(1.1).tostring();//2005-11-6 16:11:04

dt.addhours(1.1).tostring();//2005-11-5 14:53:04

dt.addmilliseconds(1.1).tostring();//2005-11-5 13:47:04

dt.addmonths(1).tostring();//2005-12-5 13:47:04

dt.addseconds(1.1).tostring();//2005-11-5 13:47:05

dt.addminutes(1.1).tostring();//2005-11-5 13:48:10

dt.addticks(1000).tostring();//2005-11-5 13:47:04

dt.compareto(dt).tostring();//0

dt.add(?).tostring();//問號為乙個時間段

dt.equals("2005-11-6 16:11:04").tostring();//false

dt.equals(dt).tostring();//true

dt.gethashcode().tostring();//1474088234

dt.gettype().tostring();

dt.gettypecode().tostring();//datetime

dt.getdatetimeformats('s')[0].tostring();//2005-11-05t14:06:25

dt.getdatetimeformats('t')[0].tostring();//14:06

dt.getdatetimeformats('y')[0].tostring();//2023年11月

dt.getdatetimeformats('d')[0].tostring();//2023年11月5日

dt.getdatetimeformats('d')[1].tostring();//2005 11 05

dt.getdatetimeformats('d')[2].tostring();//星期六 2005 11 05

dt.getdatetimeformats('d')[3].tostring();//星期六 2023年11月5日

dt.getdatetimeformats('m')[0].tostring();//11月5日

dt.getdatetimeformats('f')[0].tostring();//2023年11月5日 14:06

dt.getdatetimeformats('g')[0].tostring();//2005-11-5 14:06

dt.getdatetimeformats('r')[0].tostring();//sat, 05 nov 2005 14:06:25 gmt

string.format("",dt);//2005-11-5

string.format("",dt);//2023年11月5日

string.format("",dt);//2023年11月5日 14:23

string.format("",dt);//2023年11月5日 14:23:23

string.format("",dt);//2005-11-5 14:23

string.format("",dt);//2005-11-5 14:23:23

string.format("",dt);//11月5日

string.format("",dt);//sat, 05 nov 2005 14:23:23 gmt

string.format("",dt);//2005-11-05t14:23:23

string.format("",dt);//14:23

string.format("",dt);//14:23:23

string.format("",dt);//2005-11-05 14:23:23z

string.format("",dt);//2023年11月5日 6:23:23

string.format(C 中ToString格式大全

字元型轉換為字串 c 貨幣 2.5.tostring c 2.50 d 10進製數 25.tostring d5 25000 e 科學型 25000.tostring e 2.500000e 005 f 固定點 25.tostring f2 25.00 f?表示保持幾位小數 g 常規 2.5.tos...

C 中ToString格式大全

c 貨幣2.5.tostring c 2.50 d十進位制數 25.tostring d5 00025 e科學型 25000.tostring e 2.500000e 005 f固定點 25.tostring f2 25.00g常規 2.5.tostring g 2.5n 數字2500000.tos...

C 中ToString格式大全

c 貨幣2.5.tostring c 2.50 d十進位制數 25.tostring d5 e科學型 25000.tostring e 2.500000e 005 f固定點 25.tostring f2 25.00g常規 2.5.tostring g 2.5n 數字2500000.tostring ...