Visual Studio change date & time format

后端 未结 3 518
南笙
南笙 2021-01-12 03:07

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 c

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 03:42

    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.

提交回复
热议问题