简体   繁体   English

c# 中不遵守时间格式

[英]The time format is not respected in c#

I have the following problem I am working with Microsoft.ReportViewer.WebForms Version = 10.0.0.0 in visual studio 2010 .NET 4 I am doing an attendance report我有以下问题我在 Visual Studio 2010 .NET 4 中使用 Microsoft.ReportViewer.WebForms Version = 10.0.0.0 我正在做一个出勤报告

报告设计图片

In the Value section of the field I have the following * CDate (Fields. Time1.Value):ToString ("hh, mm tt") * I want the time to be converted to am / pm format on a windows 10 machine yes It works but when passing it to the server where the report that is a windows 2012 R2 Standard will be hosted, it does not show me that format, I attach an image of how it looks on the server在字段的值部分中,我有以下内容 * CDate (Fields.Time1.Value):ToString ("hh, mm tt") * 我希望在 windows 10 机器上将时间转换为 am / pm 格式是的有效,但是当将其传递到将托管报告为 windows 2012 R2 标准的服务器时,它没有向我显示该格式,我附上了它在服务器上的外观图像

服务器上的报告

I also tried converting it to the format like this: Convert.ToDateTime (Fields. Time1.Value):ToString ("hh: mm: ss tt") But it does not work我也尝试将其转换为如下格式: Convert.ToDateTime (Fields. Time1.Value):ToString ("hh: mm: ss tt")但它不起作用

I checked the server time format and it is correct.我检查了服务器时间格式,它是正确的。注册表设置

I am using IIS我正在使用 IIS

文化参考

Is there something else I need to configure or why is the format not up to me?还有什么我需要配置的,或者为什么格式不取决于我?

Upgrade:升级:

image upgrade图像升级

error错误

Try adding CultureInfo .尝试添加CultureInfo

date1 = new DateTime(2008, 1, 1, 18, 9, 1);
Console.WriteLine(date1.ToString("hh:mm:ss tt", 
                  CultureInfo.InvariantCulture));
// Displays 06:09:01 PM 

Source: https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/8kb3ddd4(v=vs.100)资料来源: https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/8kb3ddd4(v=vs.100)

I solved it by adding new System.Globalization.CultureInfo ("en-US")我通过添加新的 System.Globalization.CultureInfo ("en-US") 解决了这个问题

image图片

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

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