visual-studio Visual Studio 更改日期和时间格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1048373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:42:42  来源:igfitidea点击:

Visual Studio change date & time format

visual-studio-2010visual-studiovisual-studio-2012visual-studio-2013

提问by

When working in Visual Studio 2005/2008/2010/1012/2013 the dates and times are shown in mm/dd/yyyy hh:MM:ss format. Is there a way to change it to the same settings as the computer??

在 Visual Studio 2005/2008/2010/1012/2013 中工作时,日期和时间以 mm/dd/yyyy hh:MM:ss 格式显示。有没有办法把它改成和电脑一样的设置??

The displayed date that interests me is in the Watch window. My system is in non English but the Visual Studio 2005 installation is in English. So even when I have a different date format, this setting does not affect VS.

我感兴趣的显示日期在 Watch 窗口中。我的系统是非英文的,但 Visual Studio 2005 安装是英文的。所以即使我有不同的日期格式,这个设置也不会影响 VS。

TooltipQuickwatch 1Quickwatch 2

工具提示快看 1快看 2

Computer clock

电脑时钟

Computer settings

电脑设置

回答by Hans Passant

This behavior is built-in to the debugger, in the specific case that it is debugging a program written in VB.NET. Visible from the appearance of #in the screenshot. Nothing terribly unusual, the debugger in many cases makes an effort to make its output the same as the way you would have written it in a program. Take C# for example, a string that contains embedded double-quotes will be displayed with backslashes before them. Not actually present in the string, but necessary when you declare such a string literal in source code.

在调试用 VB.NET 编写的程序的特定情况下,此行为是内置于调试器中的。从#截图中的外观可见。没有什么特别不寻常的,在许多情况下,调试器会努力使其输出与您在程序中编写的方式相同。以 C# 为例,包含嵌入双引号的字符串将在显示之前带有反斜杠。实际上并不存在于字符串中,但在源代码中声明这样的字符串文字时是必需的。

So VB.NET language rules apply for the format of the literal string you see. Described in chapter 2.4.6 of the Language Specification, it is notculture sensitive. It of course can't be, your source code isn't going to produce a different program when your colleague in China compiles it. I'll just copy/paste the production rules:

因此 VB.NET 语言规则适用于您看到的文字字符串的格式。在语言规范的第 2.4.6 章中描述,它不是文化敏感的。当然不可能,当你在 CN 的同事编译它时,你的源代码不会产生不同的程序。我将复制/粘贴生产规则:

DateLiteral  ::=  #  [  Whitespace+  ]  DateOrTime  [  Whitespace+  ]  #
DateOrTime  ::=
    DateValue  Whitespace+  TimeValue  |
    DateValue  |
    TimeValue
DateValue  ::=
    MonthValue  /  DayValue  /  YearValue  |
    MonthValue  –  DayValue  -  YearValue
TimeValue  ::=
    HourValue  :  MinuteValue  [  :  SecondValue  ]  [  WhiteSpace+  ]  [  AMPM  ]  |
    HourValue  [  WhiteSpace+  ]  AMPM
MonthValue  ::=  IntLiteral
DayValue  ::=  IntLiteral
YearValue  ::=  IntLiteral
HourValue  ::=  IntLiteral
MinuteValue  ::=  IntLiteral
SecondValue  ::=  IntLiteral
AMPM  ::=  AM  |  PM

So it is always month/day/year. If you need to see the way it looks when you convert it to a string then you have to use the appropriate string conversion in your watch expression. Like CStr(Date.Now)etcetera, beware there are many ways to do it since DateTime.ToString() can take formatting characters.

所以它总是月/日/年。如果您需要查看将其转换为字符串时的外观,则必须在 watch 表达式中使用适当的字符串转换。像CStr(Date.Now)等等一样,要注意有很多方法可以做到,因为 DateTime.ToString() 可以采用格式化字符。

回答by Les Grieve

In "Control Panel\All Control Panel Items\Region and Language", on the "Formats" tab, click "Additional settings..." button. Visual Studio 2008 debugger formats dates using "Short date:" from the "Date" tab of "Customize Format".

在“控制面板\所有控制面板项目\区域和语言”中,在“格式”选项卡上,单击“其他设置...”按钮。Visual Studio 2008 调试器使用“自定义格式”的“日期”选项卡中的“短日期:”格式化日期。

Customize Format

自定义格式

QuickWatch

快看

回答by Michal Ciechan

Considering only the .ToString() is affected, are you sure that

考虑到只有 .ToString() 受到影响,你确定

Thread.CurrentThread.CurrentCulture

Thread.CurrentThread.CurrentCulture

is not being overridden or defaulted to something different than Swedish culture?

是不是被覆盖或默认为不同于瑞典文化的东西?