Argentini.Halide.H3Temporal.DateFormat C# (CSharp) Method

DateFormat() public static method

Format a date/time variable for output.
public static DateFormat ( System date, DateFormats format ) : String
date System DateTime variable to format.
format DateFormats Date format.
return String
        public static String DateFormat(System.DateTime date, DateFormats format)
        {
            string thedate = string.Empty;

            try
            {
                switch (format)
                {
                    case DateFormats.Sortable:
                        thedate = date.ToString("yyyy-MM-dd");
                        break;

                    case DateFormats.Slashes:
                        thedate = date.ToString("M/d/yyyy");
                        break;

                    case DateFormats.Dots:
                        thedate = date.ToString("M.d.yyyy");
                        break;

                    case DateFormats.Full:
                        thedate = date.ToString("dddd; MMMM d, yyyy");
                        break;

                    case DateFormats.Daily:
                        thedate = date.ToString("dddd; MMMM d");
                        break;

                    case DateFormats.Tidy:
                        thedate = date.ToString("MMM d, yyyy");
                        break;

                    case DateFormats.Weekday:
                        thedate = date.ToString("dddd");
                        break;

                    case DateFormats.WeekdayShort:
                        thedate = date.ToString("ddd");
                        break;

                    case DateFormats.Month:
                        thedate = date.ToString("MMMM");
                        break;

                    case DateFormats.MonthShort:
                        thedate = date.ToString("MMM");
                        break;

                    case DateFormats.Corporate:
                        thedate = date.ToString("M/yyyy");
                        break;

                    case DateFormats.PressRelease:
                        thedate = date.ToString("MMMM d, yyyy");
                        break;

                    case DateFormats.Rss:
                        thedate = date.ToUniversalTime().ToString("o");
            //                        thedate = date.ToString("yyyy-MM-dd") + "T" + date.ToString("HH:mm:ss") + "Z";
                        break;

                    case DateFormats.Rss2:
                        thedate = date.ToUniversalTime().ToString("R");
                        break;

                    case DateFormats.AbbreviatedFull:
                        thedate = date.ToString("ddd-MMM-dd-yyyy");
                        break;

                    case DateFormats.Friendly:

                        double days = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Days, date, System.DateTime.Now)));
                        bool future = false;

                        if (DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now) <= 0)
                        {
                            future = true;
                        }

                        thedate = "today";

                        if (Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) < 13 && Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) >= 0)
                        {
                            if (Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) < 60 && Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) > 0)
                            {
                                thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))).ToString() + " minute";

                                if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))) != 1)
                                {
                                    thedate += "s";
                                }

                                thedate += (future ? " from now" : " ago");
                            }

                            else
                            {
                                thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))).ToString() + " hour";

                                if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))) != 1)
                                {
                                    thedate += "s";
                                }

                                thedate += (future ? " from now" : " ago");
                            }
                        }

                        else
                        {
                            if (days < 7 && days > 0)
                            {
                                if (days == 1)
                                {
                                    thedate = (future ? "tomorrow" : "yesterday");
                                }

                                else
                                {
                                    thedate = days.ToString() + " day";

                                    if (days != 1)
                                    {
                                        thedate += "s";
                                    }

                                    thedate += (future ? " from now" : " ago") + ", on " + date.ToString("M/d/yyyy");
                                }
                            }

                            else
                            {
                                if (days == 7)
                                {
                                    thedate = (future ? "a week from now" : "a week ago");
                                }

                                else
                                {
                                    thedate = "on " + date.ToString("M/d/yyyy");
                                }
                            }
                        }

                        break;

                    case DateFormats.Abstract:

                        days = Math.Abs(DateDiff(DateDiffComparisonType.Days, date, System.DateTime.Now));

                        future = false;

                        if (DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now) <= 0)
                        {
                            future = true;
                        }

                        thedate = "today";

                        if (Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) < 24 && Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) >= 0)
                        {
                            if (Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) < 60 && Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) > 0)
                            {
                                thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))).ToString() + " minute";

                                if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))) != 1)
                                {
                                    thedate += "s";
                                }

                                thedate += (future ? " from now" : " ago");
                            }

                            else
                            {
                                thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))).ToString() + " hour";

                                if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))) != 1)
                                {
                                    thedate += "s";
                                }

                                thedate += (future ? " from now" : " ago");
                            }
                        }

                        else
                        {
                            if (days < 7 && days > 0)
                            {
                                if (days <= 1)
                                {
                                    thedate = (future ? "tomorrow" : "yesterday");
                                }

                                else
                                {
                                    thedate = FormatAbstract(days, "day", 0.3, 0.6, 0.8, future);
                                }
                            }

                            else
                            {
                                double weeks = days/7;

                                if (weeks < 4)
                                {
                                    thedate = FormatAbstract(weeks, "week", 0.3, 0.6, 0.8, future);
                                }

                                else
                                {
                                    double months = Math.Abs(DateDiff(DateDiffComparisonType.Months, date, System.DateTime.Now));

                                    if (months < 12)
                                    {
                                        thedate = FormatAbstract(months, "month", 0.3, 0.6, 0.8, future);
                                    }

                                    else
                                    {
                                        double years = Math.Abs(DateDiff(DateDiffComparisonType.Years, date, System.DateTime.Now));

                                        thedate = FormatAbstract(years, "year", 0.3, 0.6, 0.8, future);
                                    }
                                }
                            }
                        }

                        break;

                    default:
                        thedate = date.ToString("M-d-yyyy");
                        break;
                }
            }

            catch
            {}

            return (thedate);
        }

Same methods

H3Temporal::DateFormat ( string date, DateFormats format ) : String