intnum =10;//float num = 10;//double num = 10;stringstr;//常规数字(10)str = num.ToString("G");//千分符,逗号分隔数字,默认保留两位小数(10.00)str = num.ToString("N");//货币,C默认保留两位小数,中文系统默认格式化RMB,英文系统格式化美刀($10.00)str = num.ToString("C");//C0即不保留小...
M或 m 月日模式 显示由与当前线程关联的 DateTimeFormatInfo.MonthDayPattern 属性定义的模式或者由指定格式提供程序定义的模式。 R或 r RFC1123 模式 显示由与当前线程关联的 DateTimeFormatInfo.RFC1123Pattern 属性定义的模式或者由指定格式提供程序定义的模式。这是定义的标准,并且属性是只读的;因此,无论所使用的...
FormatDateTime的用法 声明: function FormatDateTime(const Format: string; DateTime: TDateTime): string; overload; 当然和Format一样还有一种,但这里只介绍常用的第一种 Format参数是一个格式化字符串。DateTime是时间类型。返回值是一种格式化后的 字符串 重点来看Format参数中的指令字符 c 以短时间格式显示时间,...
以下示例显示, DateTimeFormatInfo 仅当日历为公历且区域性使用纪元名称“A.D.”时,才忽略纪元名称中的标点符号。 C# 复制 using System; using System.Globalization; public class SamplesGregorianCalendar { public static void Main() { // Creates strings with punctuation and without. String strADPunc = "...
varstr=string.Format("没有继承IFormattable接口的自定义类型:{0},继承了IFormattable接口的自定义类型:{1}",newProgram(),1);Console.WriteLine(str); 1、C一格式化货币 C6代表将数字转换成当前线程国家的货币符号形式的大小并保留6位小数 代码语言:javascript ...
string.Format("{0:D}",System.DateTime.Now) 结果为:2009年3月20日 string.Format("{0:f}",System.DateTime.Now) 结果为:2009年3月20日 15:37 string.Format("{0:F}",System.DateTime.Now) 结果为:2009年3月20日 15:37:52 string.Format("{0:g}",System.DateTime.Now) 结果为:2009-3-20 15...
function FormatDateTime(const Format: string; DateTime: TDateTime): string; overload; 当然和Format一样还有一种,但这里只介绍常用的第一种,Format参数是一个格式化字符串。DateTime是时间类型。返回值是一种格式化后的字符串,重点来看Format参数中的指令字符 ...
方法/步骤 1 测试基本语法结构:DateTime dt = DateTime.Now;List<string> lt = new List<string>();//当前时间:2015年11月12日09时02分08秒258548毫秒lt.Add("{0:yyyy yyy yy y}");//格式化形式for (int i = 0; i < lt.Count; i++){Console.WriteLine("格式:" + lt[i].Replace("{", ...
string h = String.Format( "item {0} sells at {1:C}" , x, y ); Console.WriteLine(h); 1. 2. 3. 4. 5. 6. 7. 在我的机器上,可以得到下面的输出: item 16 sells at ¥3.57 1. 也许你的机器上的输出和这个不太一样。这是正常的,本文稍后就会解释这个问题。
(C.E.) in the Gregorian calendar. Format methodsTo format DateTime objects, we can use DateTime.ToString, String.Format or interpolated string syntax such as $"{now:D}". C# standard format specifiersA standard datetime format string uses a single character format specifier to define the text ...