Title: calss dates                                 If you need copy same format use firefox or chrome or safari but iexplorer not work


Preview of Code
using System;
using System.Globalization;
using System.Web;
 
public class Dates
{
    private const int startGreg = 1900;
 
    private const int endGreg = 2100;
 
    private HttpContext cur;
 
    private string[] allFormats = new string[] { "yyyy/MM/dd", "yyyy/M/d", "dd/MM/yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "yyyy-MM-dd", "yyyy-M-d", "dd-MM-yyyy", "d-M-yyyy", "dd-M-yyyy", "d-MM-yyyy", "yyyy MM dd", "yyyy M d", "dd MM yyyy", "d M yyyy", "dd M yyyy", "d MM yyyy" };
 
    private CultureInfo arCul;
 
    private CultureInfo enCul;
 
    private HijriCalendar h;
 
    private GregorianCalendar g;
 
    public Dates()
    {
        this.cur = HttpContext.Current;
        this.arCul = new CultureInfo("ar-SA");
        this.enCul = new CultureInfo("en-US");
        this.h = new HijriCalendar();
        this.g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
        this.arCul.DateTimeFormat.Calendar = this.h;
    }
 
    public int Compare(string d1, string d2)
    {
        int num;
        try
        {
            DateTime dateTime = DateTime.ParseExact(d1, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            DateTime dateTime1 = DateTime.ParseExact(d2, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            num = DateTime.Compare(dateTime, dateTime1);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("Compare :\n", exception.Message));
            num = -1;
        }
        return num;
    }
 
    public string FormatGreg(string date, string format)
    {
        string str;
        if (date.Length <= 0)
        {
            this.cur.Trace.Warn("Format :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(date, this.allFormats, this.enCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString(format, this.enCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("Date :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string FormatHijri(string date, string format)
    {
        string str;
        if (date.Length <= 0)
        {
            this.cur.Trace.Warn("Format :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(date, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString(format, this.arCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("Date :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string GDateNow()
    {
        string str;
        try
        {
            DateTime now = DateTime.Now;
            str = now.ToString("yyyy/MM/dd", this.enCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("GDateNow :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string GDateNow(string format)
    {
        string str;
        try
        {
            DateTime now = DateTime.Now;
            str = now.ToString(format, this.enCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("GDateNow :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string getShortDateStringByOmitingTime(string szDate)
    {
        if (szDate.Length <= 0)
        {
            return "";
        }
        return DateTime.Parse(szDate).ToShortDateString();
    }
 
    public string GregToHijri(string greg)
    {
        string str;
        if (greg.Length <= 0)
        {
            this.cur.Trace.Warn("GregToHijri :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(greg, this.allFormats, this.enCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString("yyyy/MM/dd", this.arCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("GregToHijri :", greg.ToString(), "\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string GregToHijri(string greg, string format)
    {
        string str;
        if (greg.Length <= 0)
        {
            this.cur.Trace.Warn("GregToHijri :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(greg, this.allFormats, this.enCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString(format, this.arCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("GregToHijri :", greg.ToString(), "\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string GTimeStamp()
    {
        return this.GDateNow("yyyyMMddHHmmss");
    }
 
    public string HDateNow()
    {
        string str;
        try
        {
            DateTime now = DateTime.Now;
            str = now.ToString("yyyy/MM/dd", this.arCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("HDateNow :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string HDateNow(string format)
    {
        string str;
        try
        {
            DateTime now = DateTime.Now;
            str = now.ToString(format, this.arCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("HDateNow :\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string HijriToGreg(string hijri)
    {
        string str;
        if (hijri.Length <= 0)
        {
            this.cur.Trace.Warn("HijriToGreg :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(hijri, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString("yyyy/MM/dd", this.enCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("HijriToGreg :", hijri.ToString(), "\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string HijriToGreg(string hijri, string format)
    {
        string str;
        if (hijri.Length <= 0)
        {
            this.cur.Trace.Warn("HijriToGreg :Date String is Empty");
            return "";
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(hijri, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            str = dateTime.ToString(format, this.enCul.DateTimeFormat);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("HijriToGreg :", hijri.ToString(), "\n", exception.Message));
            str = "";
        }
        return str;
    }
 
    public string HTimeStamp()
    {
        return this.HDateNow("yyyyMMddHHmmss");
    }
 
    public bool IsGreg(string greg)
    {
        bool flag;
        if (greg.Length <= 0)
        {
            this.cur.Trace.Warn("IsGreg :Date String is Empty");
            return false;
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(greg, this.allFormats, this.enCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            flag = (dateTime.Year < 1900 || dateTime.Year > 2100 ? false : true);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("IsGreg Error :", greg.ToString(), "\n", exception.Message));
            flag = false;
        }
        return flag;
    }
 
    public bool IsHijri(string hijri)
    {
        bool flag;
        if (hijri.Length <= 0)
        {
            this.cur.Trace.Warn("IsHijri Error: Date String is Empty");
            return false;
        }
        try
        {
            DateTime dateTime = DateTime.ParseExact(hijri, this.allFormats, this.arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
            flag = (dateTime.Year < 1900 || dateTime.Year > 2100 ? false : true);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            this.cur.Trace.Warn(string.Concat("IsHijri Error :", hijri.ToString(), "\n", exception.Message));
            flag = false;
        }
        return flag;
    }
}