123

格式化字符串与日期时间操作

using System;
class Sample
ExpandedBlockStart.gifContractedBlock.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
enum Color {Yellow = 1, Blue, Green};

    
static DateTime thisDate = DateTime.Now;

    
public static void Main() 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
// Store the output of the String.Format method in a string.
        string s = "";

        
// Format a negative integer or floating-point number in various ways.
        Console.WriteLine("Standard Numeric Format Specifiers");
        s 
= String.Format(
            
"(C) Currency: . . . . . . . . {0:C} " +
            
"(D) Decimal:. . . . . . . . . {0:D} " +
            
"(E) Scientific: . . . . . . . {1:E} " +
            
"(F) Fixed point:. . . . . . . {1:F} " +
            
"(G) General:. . . . . . . . . {0:G} " +
            
"    (default):. . . . . . . . {0} (default = 'G') " +
            
"(N) Number: . . . . . . . . . {0:N} " +
            
"(P) Percent:. . . . . . . . . {1:P} " +
            
"(R) Round-trip: . . . . . . . {1:R} " +
            
"(X) Hexadecimal:. . . . . . . {0:X} ",
            
-123-123.45f);
        Console.WriteLine(s);

        
// Format the current date in various ways.
        Console.WriteLine("Standard DateTime Format Specifiers");
        s 
= String.Format(
            
"(d) Short date: . . . . . . . {0:d} " +
            
"(D) Long date:. . . . . . . . {0:D} " +
            
"(t) Short time: . . . . . . . {0:t} " +
            
"(T) Long time:. . . . . . . . {0:T} " +
            
"(f) Full date/short time: . . {0:f} " +
            
"(F) Full date/long time:. . . {0:F} " +
            
"(g) General date/short time:. {0:g} " +
            
"(G) General date/long time: . {0:G} " +
            
"    (default):. . . . . . . . {0} (default = 'G') " +
            
"(M) Month:. . . . . . . . . . {0:M} " +
            
"(R) RFC1123:. . . . . . . . . {0:R} " +
            
"(s) Sortable: . . . . . . . . {0:s} " +
            
"(u) Universal sortable: . . . {0:u} (invariant) " +
            
"(U) Universal sortable: . . . {0:U} " +
            
"(Y) Year: . . . . . . . . . . {0:Y} ",
            thisDate);
        Console.WriteLine(s);

        
// Format a Color enumeration value in various ways.
        Console.WriteLine("Standard Enumeration Format Specifiers");
        s 
= String.Format(
            
"(G) General:. . . . . . . . . {0:G} " +
            
"    (default):. . . . . . . . {0} (default = 'G') " +
            
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer) " +
            
"(D) Decimal number: . . . . . {0:D} " +
            
"(X) Hexadecimal:. . . . . . . {0:X} ",
            Color.Green);      
        Console.WriteLine(s);
    }

}

转载于:https://www.cnblogs.com/20040583/archive/2008/10/09/1307193.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值