Search The Blog
Latest Posts
from 5whys.com
Twitter: @RoyOsherove
About this site

TDD in .NET Online Course

TDD and BDD in Ruby Online Course

 

Subscribe!

This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

« Book library management system - know a good one? | Main | VPC SP1 problems - and one bad solution »
Monday
Sep132004

Formatting Hebrew dates

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!

PrintView Printer Friendly Version

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Web Analytics