예제 #1
0
        private static DateFormatResult GetStandardFormat(char c, IFormatProvider provider)
        {
            DateTimeFormatInfo dtfi = null;

            if (provider != null)
            {
                dtfi = (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatInfo));
            }

            if (dtfi == null)
            {
                dtfi = DateTimeFormatInfo.CurrentInfo;
            }

            DateFormat df     = null;
            bool       useUtc = false;

            switch (c)
            {
            case 'd':
                df = dtfi.CreateDateFormat(DateFormat.SHORT, -1);
                break;

            case 'D':
                df = dtfi.CreateDateFormat(DateFormat.LONG, -1);
                break;

            case 'f':
                df = dtfi.CreateDateFormat(DateFormat.LONG, DateFormat.SHORT);
                break;

            case 'F':
                df = dtfi.CreateDateFormat(DateFormat.LONG, DateFormat.LONG);
                break;

            case 'g':
                df = dtfi.CreateDateFormat(DateFormat.SHORT, DateFormat.SHORT);
                break;

            case 'G':
                df = dtfi.CreateDateFormat(DateFormat.SHORT, DateFormat.LONG);
                break;

            case 't':
                df = dtfi.CreateDateFormat(-1, DateFormat.SHORT);
                break;

            case 'T':
                df = dtfi.CreateDateFormat(-1, DateFormat.LONG);
                break;

            case 'U':
                df     = dtfi.CreateDateFormat(DateFormat.LONG, DateFormat.LONG);
                useUtc = true;
                break;
            }

            if (df != null)
            {
                return(new DateFormatResult(df, false, useUtc));
            }
            return(null);
        }