C# 如何 实现 像VB 的 Format函数 一样的功能 ??
如何实现 vb 下面的功能 :
Format(12, "'D-'#")
为 D-12 Format(12, "#.00")
为 12.00 Dim d As Date
d = "06-2-6"
Label2.Text = Format(d, "yyyy-MM-dd")
为 2006-02-06
Dim d As DateTime
d = "06-2-3 12:25:23"
'大写H为24小时制
Label2.Text = Format(d, "hh点mm分ss秒")
为12点25分23秒
C# 如何实现??
如何实现 vb 下面的功能 :
Format(12, "'D-'#")
为 D-12 Format(12, "#.00")
为 12.00 Dim d As Date
d = "06-2-6"
Label2.Text = Format(d, "yyyy-MM-dd")
为 2006-02-06
Dim d As DateTime
d = "06-2-3 12:25:23"
'大写H为24小时制
Label2.Text = Format(d, "hh点mm分ss秒")
为12点25分23秒
C# 如何实现??
解决方案 »
- C#中如何实现 个位数取整(向上或向下)
- 求:dataGridView中 事件CellClick,CellMouseClick,CellContentClick的区别
- 关于c#的unicode转换问题
- WebBrowser如何获得弹出的窗口
- ACCESS文本字段被加密 这是一个字段的加密内容: :'獪蠞悍必囊缮么 实际解密后的文字应该为: A.保证车辆高速行驶 这个是什么类型的加密,请大虾们指教!
- 新手求救:c#多窗体之间线程问题!
- move_hover事件有谁用过,具体怎么用??
- 做数据库开发的时候,真的有必要象Duwamish那们起个业务实体层吗,有没必要,真接用DataSet不就行了吗???
- C#触发button后用提么人控制发送的时间
- 未将对象引用设置到对象的实例如何解决
- vs2005下用什么做报表最好,是report viewer 还是crystal report ?有没有限制?
- .NET 程序员来看
例:
DateTime d = Convert.ToDateTime("2006-2-6");
Label2.Text = d.ToString("yyyy-MM-dd");为 2006-02-06
{
string text1;
try
{
double num1;
float single1;
IFormatProvider provider1 = null;
IFormattable formattable1 = null;
if ((Expression == null) || (Expression.GetType() == null))
{
return "";
}
if ((Style == null) || (Style.Length == 0))
{
return Conversions.ToString(Expression);
}
IConvertible convertible1 = (IConvertible) Expression;
TypeCode code1 = convertible1.GetTypeCode();
if (Style.Length > 0)
{
try
{
string text2 = null;
if (Strings.FormatNamed(Expression, Style, ref text2))
{
return text2;
}
}
catch (StackOverflowException exception1)
{
throw exception1;
}
catch (OutOfMemoryException exception2)
{
throw exception2;
}
catch (ThreadAbortException exception3)
{
throw exception3;
}
catch (Exception)
{
return Conversions.ToString(Expression);
}
}
formattable1 = Expression as IFormattable;
if (formattable1 == null)
{
code1 = Convert.GetTypeCode(Expression);
if ((code1 != TypeCode.String) && (code1 != TypeCode.Boolean))
{
throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Expression" }));
}
}
switch (code1)
{
case TypeCode.Empty:
return ""; case TypeCode.Object:
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Decimal:
case TypeCode.DateTime:
return formattable1.ToString(Style, provider1); case TypeCode.DBNull:
return ""; case TypeCode.Boolean:
return string.Format(provider1, Style, new object[] { Conversions.ToString(convertible1.ToBoolean(null)) }); case TypeCode.Single:
single1 = convertible1.ToSingle(null);
if ((Style == null) || (Style.Length == 0))
{
return Conversions.ToString(single1);
}
goto Label_01C3; case TypeCode.Double:
num1 = convertible1.ToDouble(null);
if ((Style == null) || (Style.Length == 0))
{
return Conversions.ToString(num1);
}
break; case (TypeCode.DateTime | TypeCode.Object):
goto Label_01F8; case TypeCode.String:
return string.Format(provider1, Style, new object[] { Expression }); default:
goto Label_01F8;
}
if (num1 == 0)
{
num1 = 0;
}
return num1.ToString(Style, provider1);
Label_01C3:
if (single1 == 0f)
{
single1 = 0f;
}
return single1.ToString(Style, provider1);
Label_01F8:
text1 = formattable1.ToString(Style, provider1);
}
catch (Exception exception4)
{
throw exception4;
}
return text1;
}
为 Format(12, "#.00")
为 12.00
string.format("D-{0}",12) //为D-12string.format("{0}.00",12)//为 12.00