简体   繁体   中英

Change datetime to different culture

I have a datetime in this format "Wednesday, December 04, 2013". I want to translate it to different cultures at runtime so that i am able to store that in database according to culture.

This is my code:

dysMngmt.Day = curntDate.ToString("D");

The one line code above is getting the day. So,please help me.

You can use the second argument of the ToString function, which enables you to pick a culture you see fit:

curntDate.ToString("D", CultureInfo.GetCultureInfo("en-US"))

As a side note, why are you saving the date in your database as a string? Why not use a native date date type? It will take less space and allow you comparisons etc., and then you'd just use the currect culture when reading it out of the database.

Unless you have a very good reason for handling the culture of each date seperatly within the application you should set this at the application level so that the default ToString() works with your intended culture.

http://support.microsoft.com/kb/306162

Also, you should probably also not store dates as text in your database.

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