The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Formatting Hebrew dates

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Formatting Hebrew dates Posted: Sep 13, 2004 2:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Formatting Hebrew dates
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
Based on the amount of articles out there relating to hebrew dating (and I don't mean a singles bar!) there's always confusion on how exactly to translate a date into its full hebrew representation. Here's a simple method that does this, based on information which is easily available via this article.

C#
/// <summary>
  /// Returns the Juwish formatted date
  /// </summary>
  /// <param name="anyDate">Any valid date</param>
  /// <param name="addDayOfWeek">Set this option to add the day of the week to the formatted date</param>
  /// <returns>A string containing the Juwish formatted date</returns>
  public static string GetHebrewJuwishDateString(DateTime anyDate, bool addDayOfWeek)
  {
   System.Text.StringBuilder hebrewFormatedString = new System.Text.StringBuilder();
   
   // Create the hebrew culture to use hebrew (Juwish) calendar
   CultureInfo juwishCulture = CultureInfo.CreateSpecificCulture("he-IL");
   juwishCulture.DateTimeFormat.Calendar = new HebrewCalendar();
 
   #region Format the date into a Juwish format
 
   if (addDayOfWeek)
   {
    // Day of the week in the format " "
    hebrewFormatedString.Append(anyDate.ToString("dddd", juwishCulture) + " ");
   }
 
   // Day of the month in the format "'"
   hebrewFormatedString.Append(anyDate.ToString("dd", juwishCulture) + " ");
 
   // Month and year in the format " "
   hebrewFormatedString.Append("" + anyDate.ToString("y", juwishCulture));
 
   #endregion
 
   return hebrewFormatedString.ToString();
 
  }

VB.NET
''' <summary>
    ''' Summary description for JewishDateHelper.
    ''' This Class holds a single method that returns the Hebrew Jewish date format.
    ''' </summary>
    Public Class JewishDateHelper
 
        ''' <summary>
        ''' Returns the Juwish formatted date
        ''' </summary>
        ''' <param name="anyDate">Any valid date</param>
        ''' <param name="addDayOfWeek">Set this option to add the day of the week to the formatted date</param>
        ''' <returns>A string containing the Juwish formatted date</returns>
        Public Shared Function GetHebrewJuwishDateString(ByVal anyDate As DateTime, ByVal addDayOfWeek As Boolean) As String
            Dim hebrewFormatedString As System.Text.StringBuilder = New System.Text.StringBuilder
 
            '' Create the hebrew culture to use hebrew (Juwish) calendar
            Dim juwishCulture As CultureInfo = CultureInfo.CreateSpecificCulture("he-IL")
            juwishCulture.DateTimeFormat.Calendar = New HebrewCalendar
 
            If (addDayOfWeek) Then
                '' Day of the week in the format " "
                hebrewFormatedString.Append(anyDate.ToString("dddd", juwishCulture) + " ")
            End If
 
            '' Day of the month in the format "'"
            hebrewFormatedString.Append(anyDate.ToString("dd", juwishCulture) + " ")
 
            '' Month and year in the format " "
            hebrewFormatedString.Append("" + anyDate.ToString("y", juwishCulture))
 
            Return hebrewFormatedString.ToString()
 
        End Function
 
Thanks, Ido!

Read: Formatting Hebrew dates

Topic: Organization Patterns of Agile Software Development Previous Topic   Next Topic Topic: Clean URLs...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use