首页 > 解决方案 > 将“ספטמבר 15, 2018 בשעה 10:20 am”转换为日期时间 C#

问题描述

我有一个 REST api,它以字符串形式存储日期时间:“ספטמבר 15, 2018 בשעה 10:20 am” 以上包括系统语言(在本例中为希伯来语)。有什么方法可以将其转换为 C# DateTime

标签: c#datetime

解决方案


我会将所有希伯来文本转换为英文文本,然后将合适的格式字符串传递给 DateTime.TryParseExact

例如

 string dateInEnglish = dateInHebrew.Replace("ספטמבר", "September"). Replace("בשעה","")

会从那个日期去掉所有的希伯来语,尽管在实践中我会使用正则表达式。

查看 TryParseExact 上的文档以创建合适的格式字符串:

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?redirectedfrom=MSDN&view=netframework-4.7.2#System_DateTime_TryParseExact_System_String_System_String_System_IFormatProvider_System_Globalization_DateTimeStyles_System_DateTime__


推荐阅读