Visual Studio change date & time format

24,484

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.

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:

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.

Share:
24,484
Admin
Author by

Admin

Updated on May 10, 2020

Comments

  • Admin
    Admin about 4 years

    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??

    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.

    Tooltip Quickwatch 1 Quickwatch 2

    Computer clock

    Computer settings