C#字符串格式化

数值规范

也可写成int money = 368; money .ToString("C");

string.Format("金额:{0:C}", 368); => ¥368.00

string.Format("科学计数法:{0:C}", 12000.1); => 1.200001E+005

string.Format("分割数字:,{0:E0}", 123456789); => 123,456,789

string.Format("π取两位小数:{0:F2}", Math.PI); => 3.14

string.Format("16进制:{0:X4}", 33); => 0021

string.Format("百分比:{0:P0}", 0.99); => 99%

日期格式化

DateTime strDate = DateTime.Now;

也可写成strDate.ToString("Y");

string.Format("短日期格式:{0:d}", strDate); =>短日期格式:2024/4/29

string.Format("长日期格式:{0:D}", strDate); =>长日期格式:2024年4月29日

string.Format("完整日期格式:{0:f}", strDate); =>完整日期格式:2024年4月29日 16:26

string.Format("短时间格式:{0:t}", strDate); =>短时间格式:16:26

string.Format("长时间格式:{0:T}", strDate); =>长时间格式:16:26:54

string.Format("月日格式:{0:M}", strDate); =>月日格式:4月29日

string.Format("年月格式:{0:y}", strDate); =>年月格式:2024年4月

相关推荐
ccut 第一混6 小时前
c# 调用basler 相机
c#·halcon·basler
TomCode先生6 小时前
c#动态树形表达式详解
开发语言·c#
上位机付工15 小时前
C#与倍福TwinCAT3进行ADS通信
开发语言·c#
土了个豆子的16 小时前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
疯狂的维修16 小时前
c#中public类比博图
c#·自动化
土了个豆子的19 小时前
03.缓存池
开发语言·前端·缓存·visualstudio·c#
xiaowu0802 天前
策略模式-不同的鸭子的案例
开发语言·c#·策略模式
VisionPowerful2 天前
九.弗洛伊德(Floyd)算法
算法·c#
ArabySide2 天前
【C#】 资源共享和实例管理:静态类,Lazy<T>单例模式,IOC容器Singleton我们该如何选
单例模式·c#·.net core
gc_22992 天前
C#测试调用OpenXml操作word文档的基本用法
c#·word·openxml