日期时间格式化(到毫秒)

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;

public class MyClass
{
public static void RunSnippet()
{
DateTime thisDate = DateTime.Now;
DateTime utcDate = thisDate.ToUniversalTime();
//DateTime unspecifiedDate = new DateTime(2000, 3, 20, 13, 2, 3, 0, DateTimeKind.Unspecified);
DateTime unspecifiedDate = DateTime.Now;
CultureInfo ci;
string msgCulture = "Culture:";
string msgRoundtripUnspecified = "(o) Roundtrip (Unspecified):. ";

ci = Thread.CurrentThread.CurrentCulture;
Console.WriteLine("{0,-30}{1}\n", msgCulture, ci.DisplayName);
Console.WriteLine(msgRoundtripUnspecified + unspecifiedDate.ToString("o", ci));
String format="yyyyMMdd hh:mm:ss ffff";
DateTime date=DateTime.Now;
Console.WriteLine(unspecifiedDate.ToString(format, DateTimeFormatInfo.InvariantInfo));
}

#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
}



 

posted on 2011-12-13 10:59  SuperCai  阅读(1814)  评论(0编辑  收藏  举报

导航