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月

相关推荐
小堂子这厢有礼了5 小时前
Chet.QuartzNet.UI v2.3.0 大更新!表格重构 + 系统配置 + 分析页全面升级!
前端·后端·ui·重构·c#·vue
asdzx671 天前
使用 Python 精准操控 Word 字体:获取与替换方案
python·c#·word
逝水无殇1 天前
C# 特性详解
开发语言·后端·c#
LongtengGensSupreme1 天前
C#图像内存高速拷贝:使用Marshal.AllocHGlobal与ArrayPool实现内存拷贝的几个方法
开发语言·数码相机·c#
影寂ldy1 天前
C# 五大加密算法全套实战(AES/DES对称、RSA非对称、MD5/SHA256哈希)
开发语言·c#·哈希算法
互联网底层民工1 天前
异步 / 多线程并发(高频八股 · 详解版)
c#
逝水无殇1 天前
C# 反射详解
开发语言·后端·c#
神秘的MT1 天前
SQL Server 分页查询 ROW_NUMBER () OFFSET...FETCH游标(Cursor) 数据插入
数据库·sql·学习·c#·winform
我才是银古1 天前
一个人写出的 3D 几何引擎:Ara3D SDK 技术深度剖析
c#·三维几何·ai平台