简体   繁体   English

如何在 c# 中获得今天的犹太日期?

[英]How can I get today's Jewish date in c#?

I have this code:我有这个代码:

DateTime dtAnyDateHebrew = new DateTime(5767, 1, 1, new System.Globalization.HebrewCalendar());

how can I get the numeric Hebrew date of today?如何获得今天的数字希伯来日期?

Meaning:意义:

For example I want to find out if a specific Hebrew month falls in this month, so I have to send the hebrew month to the function - with today's day of month and year, so that I'll be able to check if dtAnyDateHebrew is equal to Today, bigger than.例如,我想知道本月是否有特定的希伯来月份,所以我必须将希伯来月份发送到 function - 带有今天的月份和年份,这样我就可以检查 dtAnyDateHebrew 是否相等到今天,比。 etc.等等

finally I need to get - Today's hebrew day of month, Today's hebrew month, Today's hebrew year, as int (of course).最后我需要得到 - 今天的希伯来日期,今天的希伯来月份,今天的希伯来年份,作为 int (当然)。

Can someone help me?有人能帮我吗?

Well, I found what I need:好吧,我找到了我需要的东西:

DateTime Today = DateTime.Today;

Calendar HebCal = new HebrewCalendar();
int curYear = HebCal.GetYear(Today);    //current numeric hebrew year
int curMonth = HebCal.GetMonth(Today);  //current numeric hebrew month

etc..

It's that simple.就是这么简单。

Thanks to all of you.感谢大家。

Use DateTime.Today and converted it using one of the following ex.使用DateTime.Today并使用以下前之一对其进行转换。 methods:方法:

/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using custom DateTime format string.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="format">A standard or custom date-time format string.</param>
public static string ToJewishDateString(this DateTime value, string format)
{
  var ci = CultureInfo.CreateSpecificCulture("he-IL");
  ci.DateTimeFormat.Calendar = new HebrewCalendar();      
  return value.ToString(format, ci);
}

/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using DateTime format options.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="dayOfWeek">Specifies whether the return string should
/// include the day of week.</param>
public static string ToJewishDateString(this DateTime value, bool dayOfWeek)
{
  var format = dayOfWeek ? "D" : "d";
  return value.ToJewishDateString(format);
}

This blog entry shows how.此博客条目显示了如何。

public static string GetHebrewJewishDateString(DateTime anyDate, bool addDayOfWeek)  { 
    System.Text.StringBuilder hebrewFormatedString = new System.Text.StringBuilder(); 

    // Create the hebrew culture to use hebrew (Jewish) calendar 
    CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL"); 
    jewishCulture.DateTimeFormat.Calendar = new HebrewCalendar(); 

    #region Format the date into a Jewish format 

   if (addDayOfWeek) 
   { 
      // Day of the week in the format " " 
      hebrewFormatedString.Append(anyDate.ToString("dddd", jewishCulture) + " "); 
   } 

   // Day of the month in the format "'" 
   hebrewFormatedString.Append(anyDate.ToString("dd", jewishCulture) + " "); 

   // Month and year in the format " " 
   hebrewFormatedString.Append("" + anyDate.ToString("y", jewishCulture)); 
   #endregion 

   return hebrewFormatedString.ToString(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 c# 中获得带有 UFTC 标记的今天日期? - How Can I get Today's date with UFTC stamp in c#? 我如何以mm / dd / yyyy格式以C#获取今天的日期? - How do I get today's date in C# in mm/dd/yyyy format? 如何使用C#从今天的日期和当前时间获得3个月前的日期和时间 - how to get exact 3 months ago date and time from today's date and current time using C# 如何将今天的日期与Excel的“日期”列进行比较以在C#中显示今天输入的数据 - How to compare today's date with Date of Excel column to display today's entered data in C# C#如何检查当前字符串的日期是否为今天? - C# How would I check if a date that is currently a string is today? 如何将DateTimePicker值设置为今天的日期+ 1 - How can I set a DateTimePicker value as today's date+1 如何在C#中接近不可为空的引用类型? - How can I get close to non-nullable reference types in C# today? 在 Visual C# 中,如何从标题为今天日期的列的访问表中选择数据 - In Visual C#, how do I select data from an access table from a column titled with today's date 如何在C#中的应用程序中在客户端获取远程服务器的日期和时间? - How can I get the remote server's date and time at the client side in my application in c#? C#如何检查今天是否是本月的第一个星期一? - C# How can I check if today is the first Monday of the month?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM