Converts the normal gregorian Date to hijri in YYYYMMdd format. - CSharp System

CSharp examples for System:DateTime Format

Description

Converts the normal gregorian Date to hijri in YYYYMMdd format.

Demo Code


using System.Text;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*from  w ww.java2  s  .  c  o m*/

public class Main{
        /// <summary>
        /// Converts the greg to hijri in YYYYMMdd format.
        /// </summary>
        /// <param name="dateTime">The date time.</param>
        /// <returns></returns>
        public static int ConvertGregToHijri(DateTime gregDate)
        {
            System.Globalization.UmAlQuraCalendar calendar = new System.Globalization.UmAlQuraCalendar();
            string year = calendar.GetYear(gregDate).ToString();
            string month = calendar.GetMonth(gregDate).ToString();
            if (month.Length < 2)
                month = "0" + month;
            string day = calendar.GetDayOfMonth(gregDate).ToString();
            if (day.Length < 2)
                day = "0" + day;
            return int.Parse(year + month + day);
        }
}

Related Tutorials