本文整理匯總了C#中System.DateTime.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.ToString方法的具體用法?C# DateTime.ToString怎麽用?C# DateTime.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.ToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DateTime.ToString(String format)
//引入命名空間
using System;
class MainClass
{
public static void Main()
{
DateTime myDateTime = new DateTime(2004, 1, 12, 22, 2, 10);
Console.WriteLine("myDateTime.ToString() = " + myDateTime.ToString());
Console.WriteLine("myDateTime.ToString(\"MMMM dd, yyyy\") = " + myDateTime.ToString("MMMM dd, yyyy"));
}
}
示例2: DateTime.ToString(String format, CultureInfo ci)
//引入命名空間
using System;
using System.Globalization;
public class Example21_10
{
public static void Main()
{
// create a date and a currency value
DateTime dtNow = DateTime.Now;
Double curOriginal = 12345.67;
// and format the variables for a specific culture
CultureInfo ci = new CultureInfo("en-US");
string sLocalizedDate = dtNow.ToString("d", ci);
string sLocalizedCur = curOriginal.ToString("c", ci);
// print them out
Console.WriteLine(sLocalizedDate);
Console.WriteLine(sLocalizedCur);
// and format them for a second culture
CultureInfo ci2 = new CultureInfo("en-GB");
string sLocalizedDate2 = dtNow.ToString("d", ci2);
string sLocalizedCur2 = curOriginal.ToString("c", ci2);
// print them out again
Console.WriteLine(sLocalizedDate2);
Console.WriteLine(sLocalizedCur2);
}
}