将日期转换为hijri格式。 [英] Convert date to hijri format.

查看:86
本文介绍了将日期转换为hijri格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我很抱歉我的英语不好

i希望现在将日期转换为hijri格式并以字符串格式获取如何?

请为我写代码。

谢谢。

hi
i'm sorry for my poor english
i want to convert now date to hijri format and get it in string format how?
please write code for me.
Thanks.

推荐答案

有些东西告诉我Hijri日历或伊斯兰日历可能不是.NET以标准方式支持,通过 ToString(IFormatProvider) System.DateTime.ToString(String,IFormatProvider),如果您使用接口 System.IFormatProvider 的实现,因为它是由类型 System.Globalization.CultureInfo ,因为它通常已经完成。



请参阅:

http://msdn.microsoft.com/en-us/library/ht77y576.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx [ ^ ]。



我想,这种状况的至少一个背景原因是基于特定文化的格式提供者是基于与某些国家相关的文化偏好,或者是与语言共享某些文化元素的国家集团,但伊斯兰文化传统几乎是国际性的。并且只是部分地融入了民族文化。您可以尝试尝试某些穆斯林国家的特定文化,但我不认为Hijri甚至可以在标准中包含它。您可以试试:

http://en.wikipedia.org/wiki/Hijri [ ^ ],

http://en.wikipedia.org/wiki/List_of_Muslim-majority_countries [ ^ ]。



代码示例这种方法显示在我上面引用的MSDN文章中,非常第一个链接;你可以快速尝试所有基于国家的伊斯兰文化,但我不认为你会发现案例格式为Hijri。所以,即使我最大限度地利用我的知识,你也不会成功使用.NET基类库(BCL),所以你需要应用完全自定义的方法。



首先,您可以自己开发一个Hijri特定的 System.IFormatProvider 。在更多 ad-hoc 方法中,您可以简单地开发自己的 System.DateTime.ToString 变体,这可能就像有类似的东西一样简单 string TimeToHijriString(System.DateTime time / *,some options?* /)。您所需要的就是我上面引用的日历的描述,以及使用 System.DateTime.ToString 的单个字段表示年份,月份等:

http://msdn.microsoft.com/en-us/library/system.datetime .aspx [ ^ ]。



由于Hijri每周也有12个月,每周7天,我希望你能把它映射到公历(所有计算机系统都知道) , http://en.wikipedia.org/wiki/Gregorian_calendar [ ^ ])相当不错,没有大问题。



祝你好运,

-SA
Something tells me that Hijri calendar, or "Islamic calendar" might be not supported by .NET in its standard way, through ToString(IFormatProvider) or System.DateTime.ToString(String, IFormatProvider), if you used the implementation of the interface System.IFormatProvider as it is implemented by the type System.Globalization.CultureInfo, as it is usually done.

Please see:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^],
http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx[^].

I think, at least one background reason of such state of affairs is that the format providers based on particular cultures, are based on cultural preferences related to certain nations, or group of nations sharing some cultural elements such as language, but Islamic cultural traditions are pretty much international and only partially integrate in national cultures. You can take a chance of trying particular cultures of some Muslim countries, but I don't think that Hijri dominates even there to the extent that it can be included in the standard. You could just try though:
http://en.wikipedia.org/wiki/Hijri[^],
http://en.wikipedia.org/wiki/List_of_Muslim-majority_countries[^].

The code sample for such approach is shown in a MSDN article I referenced above, very first link; you can quickly try all country-based Islamic cultures, but I don't think you will find the case formatting as Hijri. So, even though I'm to best of my knowledge, you won't success in using just .NET Base Class Library (BCL), so you will need to apply fully custom approach.

First of all, you can develop a Hijri-specific of the System.IFormatProvider by yourself. In a more ad-hoc approach, you can simply develop your own variant of System.DateTime.ToString which could be as simple as having something like string TimeToHijriString(System.DateTime time /* , some options? */). All you would need is the description of the calendar I referenced above, plus using individual fields of System.DateTime.ToString for year, month, etc.:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

As the Hijri also has 12 months per year, 7 days a week, I hope you can map it to the Gregorian calendar (known to all computer systems, http://en.wikipedia.org/wiki/Gregorian_calendar[^]) pretty well, without big problems.

Wish you the best of luck,
—SA






使用此方法从Hi转换jri to Gregorian



Hi,

Use this Method to convert from Hijri to Gregorian

public static string ConvertDateCalendar(DateTime DateConv, string Calendar, string DateLangCulture)
      {
          DateTimeFormatInfo DTFormat;
          DateLangCulture = DateLangCulture.ToLower();
          /// We can't have the hijri date writen in English. We will get a runtime error

          if (Calendar == "Hijri" && DateLangCulture.StartsWith("en-"))
          {
              DateLangCulture = "ar-sa";
          }

          /// Set the date time format to the given culture
          DTFormat = new System.Globalization.CultureInfo(DateLangCulture, false).DateTimeFormat;

          /// Set the calendar property of the date time format to the given calendar
          switch (Calendar)
          {
              case "Hijri":
                  DTFormat.Calendar = new System.Globalization.HijriCalendar();
                  break;

              case "Gregorian":
                  DTFormat.Calendar = new System.Globalization.GregorianCalendar();
                  break;

              default:
                  return "";
          }

          /// We format the date structure to whatever we want
          DTFormat.ShortDatePattern = "dd/MM/yyyy";
          return (DateConv.Date.ToString("f", DTFormat));
      }





如何使用





How to use

string date = ConvertDateCalendar(DateTime.Now, "Hijri", "en-US")





希望这可以帮到你



Hope this may help you


这篇关于将日期转换为hijri格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆