110,534
社区成员
发帖
与我相关
我的任务
分享
DateTime date1 = new DateTime(2008, 4, 10, 6, 30, 0);
Console.WriteLine(date1.ToString("MMM dd HH:mm:ss yyyy",
CultureInfo.CreateSpecificCulture("en-US")));
using System;
using System.Collections.Generic;
using System.Globalization;
public class MyClass
{
public static void RunSnippet()
{
DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
string _time = "Oct 27 13:00:01 2009";
DateTime dt = DateTime.ParseExact(_time, "MMM dd HH:mm:ss yyyy", dtfi);
WL(dt.ToString());
RL();
}
#region Helper methods
public static void Main()
{
try
{
RunSnippet();
}
catch (Exception e)
{
string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
Console.WriteLine(error);
}
finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}
DateTime date1 = new DateTime(2008, 4, 10);
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("en-US")));
// Displays Thursday, April 10, 2008
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("pt-BR")));
// Displays quinta-feira, 10 de abril de 2008
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("es-MX")));
// Displays jueves, 10 de abril de 2008
using System.Globalization;
DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
string _time = "Oct 27 13:00:01 2009";
DateTime dt = DateTime.ParseExact(_time, "MMM dd HH:mm:ss yyyy", dtfi);
Console.WriteLine(dt.ToString());