Visual Studio更改日期和时间格式

时间:2023-01-14 23:30:46

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.

Visual Studio更改日期和时间格式Visual Studio更改日期和时间格式Visual Studio更改日期和时间格式

Visual Studio更改日期和时间格式

Visual Studio更改日期和时间格式

4 个解决方案

#1


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 not culture 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章中描述,它不是文化敏感的。它当然不可能,当你在中国的同事编写它时,你的源代码不会产生不同的程序。我只是复制/粘贴生产规则:

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.

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

#2


As Benjol suggested that stating where you are seeing the date would have been better but wherever the date and time is being shown, I put my money on this answer:

正如Benjol建议说明你所看到的日期本来会更好,但无论日期和时间在哪里展示,我都把钱放在这个答案上:

The dates are shown in the given format because you told it to do so. More specifically, it is your operating system date time formatting settings which governs most of the places including Visual Studio.

日期以给定的格式显示,因为您告诉它这样做。更具体地说,它是您的操作系统日期时间格式设置,它管理大多数地方,包括Visual Studio。

To confirm this, change the formatting options (Control Panel > Regional Settings) of date time and see if it works.

要确认这一点,请更改日期时间的格式选项(控制面板>区域设置),看它是否有效。

#3


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

只考虑.ToString()会受到影响,你确定吗?

Thread.CurrentThread.CurrentCulture

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

是不是被超越或拖欠了与瑞典文化不同的东西?

#4


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

#1


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 not culture 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章中描述,它不是文化敏感的。它当然不可能,当你在中国的同事编写它时,你的源代码不会产生不同的程序。我只是复制/粘贴生产规则:

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.

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

#2


As Benjol suggested that stating where you are seeing the date would have been better but wherever the date and time is being shown, I put my money on this answer:

正如Benjol建议说明你所看到的日期本来会更好,但无论日期和时间在哪里展示,我都把钱放在这个答案上:

The dates are shown in the given format because you told it to do so. More specifically, it is your operating system date time formatting settings which governs most of the places including Visual Studio.

日期以给定的格式显示,因为您告诉它这样做。更具体地说,它是您的操作系统日期时间格式设置,它管理大多数地方,包括Visual Studio。

To confirm this, change the formatting options (Control Panel > Regional Settings) of date time and see if it works.

要确认这一点,请更改日期时间的格式选项(控制面板>区域设置),看它是否有效。

#3


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

只考虑.ToString()会受到影响,你确定吗?

Thread.CurrentThread.CurrentCulture

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

是不是被超越或拖欠了与瑞典文化不同的东西?

#4


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