3

我想将日期转换为欧洲格式并将其显示在网格视图列中,谁能告诉我该怎么做?

这是我的代码:

EventManagerDataContext db = new EventManagerDataContext();

if (txtSearchnews.Text == "")
{
    var q = from a in db.EMR_NEWs

    select new
    {
        News_ID=a.News_ID,
        Title=a.Title,
        Text=a.Text,
        Creation_Date=a.Creation_Date,
        Publication_Date=a.Publication_Date,
        Expiration_Date=a.Expiration_Date
    };
    grid.DataSource = q.ToList();
}
4

3 回答 3

3

What you're after is Globalization.

You should check out CultureInfo in .NET.

Using that you can set the culture of your thread to a specific culture, meaning that numbers and dates can be formatted accordingly.

Furthermore, you can access or use NumberFormatInfo or DateTimeFormatInfo of not only your own culture/current threads culture, but also as objects you can use in various parse and tostring methods.

Understanding those are valurable to being able to do cross-country/cross-format applications, so I can only advice you to look them up and play around whit them. Then when understanding them more, you'll find many ways to solve your specific issue

于 2013-10-24T05:45:15.730 回答
2

重新格式化日期后做一件事写这个

DateTime dt = Convert.ToDateTime(strFormatedDate);

*strFormatedDate*保存格式化日期的字符串变量在哪里。

现在你有了 DateTime 格式的日期,所以继续你的功能。

我希望它会成功!

于 2013-10-24T05:39:36.653 回答
0

我找到了这样的解决方案:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");

Creation_Date = TimeZoneInfo.ConvertTime(a.Creation_Date,tzi),
于 2013-10-24T08:32:37.693 回答