How to get local machine date format.如何获取本机时间格式

Sometimes we need to get local machine date format string.Example The User tell us  they want to see the date has same format as their compute.

I spent some time to find the method by using Google,but I failed. At last I found the way by myself.And below is my method.

    CultureInfo cultureInfo=CultureInfo.CurrentCulture;

    string localMachineShortDateFormat=cultureInfo.DateTimeFormat.ShortDatePattern;

Finally I found a very very easy way

DateTimeFormatInfo.CurrentInfo.ShortDatePattern 

 

And I got some useful code.

    CultureInfo currCI = System.Threading.Thread.CurrentThread.CurrentCulture;
    CultureInfo engCI = new CultureInfo("en-US",false);
    System.Threading.Thread.CurrentThread.CurrentCulture = engCI;

 

And I got some puzzles too.

    CultureInfo destCI = System.Threading.Thread.CurrentThread.CurrentCulture;
    CultureInfo osCI = System.Globalization.CultureInfo.InstalledUICulture;
    CultureInfo overrideCI = LanguageManager.SystemCultureInfo;

posted on 2010-06-22 10:39  林骄  阅读(517)  评论(0)    收藏  举报