简体   繁体   中英

Writing Date Value

I am writing some date values in US format (MMDDYYYY) using my programme to a csv file in c#. This is a WPF Application. If a user has different regional settings like UK in their computers the date values are flipping. how can i make sure that no matter what the users regional settings are my application will write the date values in the US format?

You can specify the format when converting the date to a string (I'm not sure if that's how you are displaying the date, though):

DateTime d = DateTime.Now;
string s = d.ToString("MMddyyyy");

For more detail on the date format string see: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Console.WriteLine(dateToDisplay.ToString("MMddyyyy"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM