我使用humanizer来获取人类友好的字符串,该字符串告诉我某个日期在时间上向前或向后移动了多远。下面是一些示例:
DateTime.UtcNow.AddHours(-30).Humanize() => "yesterday"
DateTime.UtcNow.AddHours(-2).Humanize() => "2 hours ago"
DateTime.UtcNow.AddHours(30).Humanize() => "tomorrow"
DateTime.UtcNow.AddHours(2).Humanize() => "2 hours from now"
DateTimeOffset.AddHours(1).Humanize() => "an hour from now"该库为不同区域性提供了功能:
public static string Humanize(this DateTime input, bool utcDate = true, DateTime? dateToCompareAgainst = null, CultureInfo culture = null)我的用法(使用波斯文化)是:
myDate.Humanize(culture: new CultureInfo("fa-IR"))问题是它在Visual Studio 2013中的IIS Express中工作得很好,但在windows 8中它在IIS中显示英语。
所以我的结果是:
"14 days ago" //In IIS
"14 روز پیش" //In Visual Studio 2013发布于 2020-09-01 17:50:31
这个问题现在看起来很老了,可能已经解决了。在WindowsFramework3.5及更早版本中,文化数据由.NET操作系统和.NET框架提供。也许这就是通过IIS运行和通过Visual Studio本地运行之间存在差异的原因。
如果您的项目无法更新,这里有一个添加波斯语的解决方法。https://www.codeproject.com/Articles/32096/How-to-Set-PersianCalendar-to-CultureInfo
https://stackoverflow.com/questions/36171751
复制相似问题