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月

相关推荐
没什么本事11 小时前
关于C# panel 添加lable问题 -- 明确X和Y 位置错误
android·java·c#
火星papa13 小时前
C# 实现平滑流畅的进度条ProgressBar
c#·进度条·progressbar·平滑流畅
游乐码15 小时前
UnityGUI(五)GUI控件综合使用
开发语言·unity·c#
程序leo源15 小时前
C语言知识总结
c语言·开发语言·c++·经验分享·笔记·青少年编程·c#
烛阴16 小时前
TEngine 入门系列(二):三件套环境搭建 -- Unity + TEngine + AI 助手
前端·c#·unity3d
The Shio20 小时前
OptiByte 操练场:面向 IoT/嵌入式的协议可视化调试工具
网络·嵌入式硬件·物联网·c#·.net·业界资讯·iot
龙侠九重天21 小时前
C# 调用 TensorFlow:迁移学习与模型推理实战指南
人工智能·深度学习·机器学习·c#·tensorflow·迁移学习·tensorflow.net
我是唐青枫1 天前
C#.NET YARP 认证授权实战:在网关层统一接入 JWT
开发语言·c#·.net
程序leo源1 天前
Linux深度理解
linux·运维·服务器·c语言·c++·青少年编程·c#
白菜上路1 天前
C# .net 生成版本号自动变更
c#·.net·visual studio