为什么在使用当前时间格式化DateTime时会得到2555年?

sha*_*oth 1 .net c# datetime azure azure-storage

我有C#代码执行以下操作:

 DateTime now = DateTime.UtcNow;
 string timeToOutput = now.ToString();
 String pathInStorage = now.ToString("yyyy-MM-dd/HH/");

 CloudBlobClient client = getClient();
 CloudBlobContainer container = client.GetContainerReference(hardcodedContainerName);
 container.GetBlobReference(pathInStorage).UploadText(timeToOutput);
Run Code Online (Sandbox Code Playgroud)

如您所见,我首先获取当前时间,然后使用不同的格式字符串将其格式化两次.现在大多数情况下,存储中的路径将与输出到blob本身的时间相匹配.

然而,有时(非常罕见)blob的时间将是2012年(如2012年10月29日12:33:00),但路径将包含2555年和小时 - 月 - 月将匹配blob内的时间(喜欢2555-10-29-12).

怎么会发生这种情况?

ya2*_*a23 6

2555年是泰国太阳能日历的 2012年.不知道你为什么会这样,也许执行代码的服务器有一个泰语区域设置?

要使代码按预期运行,请使用不同的,区域设置感知的ToString()版本.请参见DateTime.ToString()