英式时间格式

Fri, 14 Oct 2011 10:49:46 GMT
Friday, 14 October 2011
Fri,14 October 2011

 

DateTime dt = DateTime.Now;

Response.Write(string.Format("{0:R}", dt));
Response.Write("<br/>");
Response.Write(dt.ToString("D", DateTimeFormatInfo.InvariantInfo));
Response.Write("<br/>");
Response.Write(dt.ToString("ddd,dd MMMM yyyy", DateTimeFormatInfo.InvariantInfo));

 

前台Html页面绑定的参数<%# ChangeDate(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "PrintDate")))%>;

"PrintDate"为后台绑定的参数,

亦如:

<div> <%# Eval("Town")%></div>
<div> <%# Eval("County")%></div>

 

后台编写ChangDate()方法,如下:

        /// <summary>
        /// English Date
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public string ChangeDate(DateTime date)
        {
            string interDate = date.ToString("dddd,d MMMM yyyy", DateTimeFormatInfo.InvariantInfo);
            string[] dateArray = interDate.Split(new char[2] { ',', ' ' });  //根据','和' '分割
            string engDate;
            string week = dateArray[0];
            switch (week)
            {
                case "Monday":
                    week="Mon";
                    break;
                case "Tuesday":
                    week="Tues";
                    break;
                case "Wednesday":
                    week="Wed";
                    break;
                case "Thursday":
                    week="Thurs";
                    break;
                case "Friday":
                    week="Fri";
                    break;
                case "Saturday":
                    week="Sat";
                    break;
                case "Sunday":
                    week="Sun";
                    break;
            }
            string day = dateArray[1];
            switch (day)
            {
                case "1":
                case "21":
                case "31":
                    day += "st";
                    break;
                case "2":
                case "22":
                    day += "nd";
                    break;
                case "3":
                case "23":
                    day += "rd";
                    break;
                default:
                    day += "th";
                    break;
            }
            engDate = week + "," + day + " " + dateArray[2] + " " + dateArray[3];
            return engDate;
        }

格式:Tues,11th October 2011

 

ok完成~

 

后记:

(1)Splite在MSDN上的讲解还是很详细的,暂时没看

(2)Eval,DataBinder.Eval 前台绑定数据的区别,还没有搞懂

posted @ 2011-10-17 18:44  zhanglong0426  阅读(674)  评论(0编辑  收藏  举报