First , about the date time rules:
规范 | DateTimeFormatInfo属性 | 模式的价值(en - US文化) |
---|---|---|
t | ShortTimePattern | h:mm tt |
d | ShortDatePattern | M/d/yyyy |
T | LongTimePattern | h:mm:ss tt |
D | LongDatePattern | dddd, MMMM dd, yyyy |
f | (组合D t T ) | dddd, MMMM dd, yyyy h:mm tt |
F | FullDateTimePattern | dddd, MMMM dd, yyyy h:mm:ss tt |
g | (组合d t T ) | M/d/yyyy h:mm tt |
G | (组合d T T ) | M/d/yyyy h:mm:ss tt |
m M M | MonthDayPattern | MMMM dd |
y Y Y | YearMonthPattern | MMMM, yyyy |
r R R | RFC1123Pattern | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*) |
s | SortableDateTimePattern | yyyy'-'MM'-'dd'T'HH':'mm':'ss (*) |
u | UniversalSortableDateTimePattern | yyyy'-'MM'-'dd HH':'mm':'ss'Z' (*) |
(*)=文化独立 |
1++++++++++++++++++++++++++++++++++++++++++++
DateTime dt = DateTime.Now;
// Set the CurrentCulture property to U.S. English.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
// Display dt, formatted using the ShortDatePattern.
// and the CurrentThread.CurrentCulture.
Console.WriteLine(dt.ToString("G"));
// Create a CultureInfo object for German in Germany.
CultureInfo ci = new CultureInfo("de-DE");
// Display dt, formatted using the ShortDatePattern
// and the CultureInfo object.
Console.WriteLine(dt.ToString("d", ci));
2+++++++++++++++++++++++++++++++++++++++++++++++
CultureInfo myCultureInfo = new CultureInfo("de-DE");
CultureInfo myCultureInfo1 = new CultureInfo("en-US");
string myString = "27.09.2011 13:53:36";
string myString1 = "9/27/2011 1:57:14 PM";
DateTime dateD = DateTime.Parse(myString, myCultureInfo);
DateTime dateE = DateTime.Parse(myString, myCultureInfo1);
Console.WriteLine(dateD);
Console.WriteLine(dateE);
3+++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Globalization;
public class SamplesCultureInfo
{
public static void Main()
{
// Prints the header.
Console.WriteLine("SPECIFIC CULTURE PARENT CULTURE");
// Determines the specific cultures that use the Chinese language, and displays the parent culture.
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if (ci.TwoLetterISOLanguageName == "zh")
{
Console.Write("0x{0} {1} {2,-40}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName);
Console.WriteLine("0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName);
}
}
}
}
public class SamplesCultureInfo
{
public static void Main()
{
// Prints the header.
Console.WriteLine("SPECIFIC CULTURE PARENT CULTURE");
// Determines the specific cultures that use the Chinese language, and displays the parent culture.
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
if (ci.TwoLetterISOLanguageName == "zh")
{
Console.Write("0x{0} {1} {2,-40}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName);
Console.WriteLine("0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName);
}
}
}
}