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月

相关推荐
幻想趾于现实13 小时前
C# Winform 入门(15)之制作二维码和拼接(QR)
开发语言·c#·winform
霸道流氓气质13 小时前
Winform入门进阶企业级开发示例:http接口数据清洗转换、断线续传、mqtt数据传输实例详解(附代码资源下载)
http·c#·winform
Eiceblue17 小时前
C# 设置Excel中文本的对齐方式、换行、和旋转
开发语言·c#·excel
du fei19 小时前
C# 串口通信
开发语言·c#
DXM05211 天前
ArcGIS Engine开发教程--从零搭建GIS桌面应用
大数据·数据库·arcgis·c#·arcgis engine·arcgis engine开发
专注VB编程开发20年1 天前
WebView2最低支持.NET frame4.5,win7系统
c#·.net·webview2·vb.net
时光追逐者1 天前
一款基于 .NET 8 + Vue 开源的、企业级中后台权限管理系统
前端·vue.js·microsoft·开源·c#·.net·.netcore
整点薯条吃吃喽1 天前
C,C++,C#
c语言·c++·c#
专注VB编程开发20年1 天前
C#,VB.NET正则表达式法替换代码
正则表达式·c#·.net·vb.net
局外人_Jia1 天前
【 C# 使用 MiniExcel 库的典型场景】
开发语言·windows·c#·miniexcel