My co-worker and I were debugging an issue when we came across something curious: the same bit of VB code produces a different output on my machine versus his. We cannot figure out why.
The code:
Dim textForMatching = unmatchedRecord.MetaDataString + " - " + unmatchedEvent.StartDate?.ToLocalTime().Date
On my machine, the output would be something like 10d775fff794 - 06/15/2023
while on his machine the output is 10d775fff794 - 6/15/2023
. That leading 0
in my date output is missing from his.
We’re in the same time-zone and we’re both using the same version of Visual Studio.
Does anyone know why this happens? It is some localization interplay due to the implicit conversion to a string by using the +
operator? Or are there settings on our computers which could be slightly different and lead to this?
2
Answers
Check your registry:
HKEY_CURRENT_USERControl PanelInternational
the sShortDate setting. Is it different on each machine?I believe this is how it determines the date format to use.
You should study the documentation.
Then you’ll find:
So, the reason is that you are using different Windows settings for date and time.