/// <summary> /// Generates a date adjusted to the user's timezone. Returns empty string if the date is not valid. /// </summary> /// <param name="xmldatetime">The date time in XML/ISO8601 as a string. In SQL, use this: CONVERT(varchar(24), [Column], 126)</param> /// <param name="dateFormat">The output date format.</param> /// <param name="user">The current user.</param> public static string AdjustAndDisplayDate(DateTime date, ConversionDateFormatType dateFormat, UserInfo user) { if (date == DateTime.MinValue) { return(String.Empty); } return(Conversion.TranslateDate(AdjustDateTime(date, false, user), System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName, dateFormat)); }
/// <summary> /// Returns the date string in proper format, respective of the language. /// </summary> /// <param name="dt">The date to output.</param> /// <param name="langcode">The current language ID.</param> /// <param name="dateformat">Specifies how to format the returned date string.</param> /// <param name="addtz">Whether or not to add timezone information to the end of the date string.</param> public static string TranslateDate(this DateTime dt, string langcode, ConversionDateFormatType dateformat, bool addtz) { string dateformatstr; //Return empty string if the DateTime is the min value if (dt == DateTime.MinValue) { return(""); } switch (dateformat) { case ConversionDateFormatType.FullDateTime: dateformatstr = "dddd, MMMM dd, yyyy h:mm tt"; //6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM (en-US) break; case ConversionDateFormatType.LongDate: dateformatstr = "dddd, MMMM dd, yyyy"; //6/15/2009 1:45:30 PM -> Monday, June 15, 2009 (en-US) break; case ConversionDateFormatType.ShortDate: dateformatstr = "MM/dd/yyyy"; //6/15/2009 1:45:30 PM -> 6/15/2009 (en-US) break; case ConversionDateFormatType.MonthName: dateformatstr = "MMMM"; //6/15/2009 1:45:30 PM -> June break; case ConversionDateFormatType.ShortMonthName: dateformatstr = "MMM"; //6/15/2009 1:45:30 PM -> Jun break; case ConversionDateFormatType.ShortTime: dateformatstr = "h:mm tt"; //6/15/2009 1:45:30 PM -> 1:45 PM break; case ConversionDateFormatType.LongTime: dateformatstr = "h:mm:ss tt"; //6/15/2009 1:45:30 PM -> 1:45:30 PM break; default: dateformatstr = "MM/dd/yyyy h:mm tt"; //6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM (en-US) break; } return(dt.ToString(dateformatstr, CultureInfo.CreateSpecificCulture(langcode)) + (addtz ? " EST (GMT -5:00)" : "")); }
/// <summary> /// Generates a date adjusted to the user's timezone. Returns empty string if the date is not valid. /// </summary> /// <param name="xmldatetime">The date time in XML/ISO8601 as a string. In SQL, use this: CONVERT(varchar(24), [Column], 126)</param> /// <param name="dateFormat">The output date format.</param> /// <param name="user">The current user.</param> public static string AdjustAndDisplayDate(string xmldatetime, ConversionDateFormatType dateFormat, UserInfo user) { return(AdjustAndDisplayDate(Conversion.XMLDateToDateTime(xmldatetime), dateFormat, user)); }
/// <summary> /// Returns the date string in proper format, respective of the language. /// </summary> /// <param name="datestring">The date in XML date string (ISO 8601) format.</param> /// <param name="langcode">The current language ID.</param> /// <param name="dateformat">Specifies how to format the returned date string.</param> /// <param name="addtz">Whether or not to add timezone information to the end of the date string.</param> public static string TranslateDate(this string datestring, string langcode, ConversionDateFormatType dateformat, bool addtz) { return(TranslateDate(XMLDateToDateTime(datestring), langcode, dateformat, addtz)); }
/// <summary> /// Returns the date string in proper format, respective of the language. /// </summary> /// <param name="datestring">The date in XML date string (ISO 8601) format.</param> /// <param name="langcode">The current language ID.</param> /// <param name="dateformat">Specifies how to format the returned date string.</param> public static string TranslateDate(this string datestring, string langcode, ConversionDateFormatType dateformat) { return(TranslateDate(datestring, langcode, dateformat, false)); }
/// <summary> /// Returns the date string in proper format, respective of the language. /// </summary> /// <param name="dt">The date to output.</param> /// <param name="langcode">The current language ID.</param> /// <param name="dateFormatType">Specifies how to format the returned date string.</param> public static string TranslateDate(this DateTime dt, string langcode, ConversionDateFormatType dateFormatType) { return(TranslateDate(dt, langcode, dateFormatType, false)); }