1

I'm working with two servers (Server 2012 Std) and (Server 2016).

On 2012 when I run the command:

[System.DateTime]::UtcNow.ToString([System.Globalization.CultureInfo]::GetCultureInfo("en-NZ"))

I get back the result:

13/03/2018 12:49:55 a.m.

When I run the same command as above on my Server 2016 I get back:

13/03/2018 12:48:42 AM

They key part is the AM/PM formatting. I'm trying to understand why these are returning different results and how to get the server 2016 output to be formatted the same as the first. This is due to an application requirement and I do not have access to change the application to format the string so I have to resolve this at the OS level somehow.

Jake Nelson
  • 1,748
  • 13
  • 22
  • Culture Info retreives the Cultures as defined in Windows. These can change with the smalest update. Personally I think the Server 2012 results looks faulty/less clear. It might be something they fixed. – Christopher Mar 13 '18 at 01:21
  • Btb, you can look up waht is defined in your Windows in teh Region setings: https://support.office.com/en-us/article/change-the-windows-regional-settings-to-modify-the-appearance-of-some-data-types-edf41006-f6e2-4360-bc1b-30e9e8a54989 – Christopher Mar 13 '18 at 01:24
  • If this is not a coding question but a server setup issue then I'm not sure it's on topic for SO. Maybe https://serverfault.com/? – juharr Mar 13 '18 at 02:09
  • @juharr there is no server configuration to override locale data changes. So I don't think it would be good fit as server administration question. Could be closed as duplicate so - something like "create custom CultureInfo" (https://stackoverflow.com/questions/12916940/creating-custom-cultureinfo-for-country-language-combination) or one linked in the answer https://stackoverflow.com/questions/31888839/output-of-times-am-pm-changed-in-windows-10-when-using-datetime-tostringtt – Alexei Levenkov Mar 13 '18 at 02:40

2 Answers2

4

Take a look at Output of times (AM/PM) changed in Windows 10 when using DateTime.ToString("tt") for some discussion of this.

It doesn't appear that you will be able to fix this without changing application code.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
0

I found the same problem and I was able to get around the issue by using the following code. Not sure if that's what your looking for.

[System.DateTime]::UtcNow.ToString("dd/MM/yyyy hh:mm:ss tt")
Neel Patel
  • 31
  • 2
  • 7
  • Unfortunately I have no ability to change the code in the application or manipulate the string outputted by the GetCultureInfo() method. – Jake Nelson Mar 13 '18 at 01:35
  • Ah I see. Only other alternative as mentioned in the discussion outlined by Robert is to change the how the AM/PM symbols are handled by the OS. Of course that would require changing the time settings in the OS. That may not be a viable solution if you're using the application on random/unlisted servers. It also seems like a drastic measure to change the time setup for each server using the application. – Neel Patel Mar 13 '18 at 02:05