ToString() public static method

public static ToString ( System.DateTime dt, System.TimeSpan utc_offset, string format, DateTimeFormatInfo dfi ) : string
dt System.DateTime
utc_offset System.TimeSpan
format string
dfi DateTimeFormatInfo
return string
示例#1
0
        public string ToString(string format, IFormatProvider formatProvider)
        {
            DateTimeFormatInfo dfi = DateTimeFormatInfo.GetInstance(formatProvider);

            if (format == null || format == String.Empty)
            {
                format = dfi.ShortDatePattern + " " + dfi.LongTimePattern + " zzz";
            }

            bool to_utc = false, use_invariant = false;

            if (format.Length == 1)
            {
                char fchar = format [0];
                try {
                    format = DateTimeUtils.GetStandardPattern(fchar, dfi, out to_utc, out use_invariant, true);
                } catch {
                    format = null;
                }

                if (format == null)
                {
                    throw new FormatException("format is not one of the format specifier characters defined for DateTimeFormatInfo");
                }
            }
            return(to_utc ? DateTimeUtils.ToString(UtcDateTime, TimeSpan.Zero, format, dfi) : DateTimeUtils.ToString(DateTime, Offset, format, dfi));
        }
示例#2
0
 public static string ToString(DateTime dt, string format, DateTimeFormatInfo dfi)
 {
     return(DateTimeUtils.ToString(dt, null, format, dfi));
 }