简体   繁体   English

将日期时间更改为其他文化

[英]Change datetime to different culture

I have a datetime in this format "Wednesday, December 04, 2013". 我的日期时间格式为“ 2013年12月4日,星期三”。 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: 您可以使用ToString函数的第二个参数,它使您可以选择自己认为合适的区域性:

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. 除非有很好的理由在应用程序中分别处理每个日期的区域性,否则应在应用程序级别进行设置,以使默认的ToString()与您想要的区域性一起使用。

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

Also, you should probably also not store dates as text in your database. 另外,您可能还不应该将日期作为文本存储在数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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