/// <summary>将日期数据转换成字符串</summary> /// <param name="VarDateTime">日期数据</param> /// <param name="IntDateType">转换格式:0-普通,1-长日期,2-长时间,3-短日期,4-短时间,5-中文日期,6-中文时间,7-中文日期时间</param> /// <returns>返回字符串</returns> public static string DateToStr(System.DateTime VarDateTime, int IntDateType) { string udate = ""; switch (IntDateType) { case 1: udate = VarDateTime.ToLongDateString(); break; case 2: udate = VarDateTime.ToLongTimeString(); break; case 3: udate = VarDateTime.ToShortDateString(); break; case 4: udate = VarDateTime.ToShortTimeString(); break; case 5: { udate = VarDateTime.Year.ToString() + "年"; udate += VarDateTime.Month.ToString() + "月"; udate += VarDateTime.Day.ToString() + "日"; break; } case 6: { udate = VarDateTime.Hour.ToString() + "时"; udate += VarDateTime.Minute.ToString() + "分"; udate += VarDateTime.Second.ToString() + "秒"; break; } case 7: { udate = VarDateTime.Year.ToString() + "年"; udate += VarDateTime.Month.ToString() + "月"; udate += VarDateTime.Day.ToString() + "日 "; udate += VarDateTime.Hour.ToString() + "时"; udate += VarDateTime.Minute.ToString() + "分"; udate += VarDateTime.Second.ToString() + "秒"; break; } default: udate = VarDateTime.ToString(); break; } return udate; }
public string GetDateString(System.DateTime date) { if (string.IsNullOrEmpty(Format) == false) { return date.ToString(Format); } if(stringType == DateTimeStringType.ToString) { return date.ToString(); } else if(stringType == DateTimeStringType.ToLongDateString) { return date.ToLongDateString(); } else if(stringType == DateTimeStringType.ToLongTimeString) { return date.ToLongTimeString(); } else if( stringType == DateTimeStringType.ToShortDateString) { return date.ToShortDateString(); } else if(stringType == DateTimeStringType.ToShortTimeString) { return date.ToShortTimeString(); } return date.ToString(); }
/// <summary> /// Trả về chuỗi date có dạng 01/01/2009 AM(hoặc PM) /// </summary> /// <param name="_Date"></param> /// <returns></returns> public static string ToShortDateString(System.DateTime _Date) { string AMPM = ""; if (_Date.ToString().Contains("AM")) { AMPM = "AM"; } else { AMPM = "PM"; } return Strings.Right("0" + _Date.Day.ToString(), 2) + "/" + Strings.Right("0" + _Date.Month.ToString(), 2) + "/" + _Date.Year.ToString() + " " + _Date.ToLongTimeString(); //_Date.ToShortDateString & " " & _Date.ToLongTimeString ' }
private void updateText(System.DateTime dt) { if (this.PickDate && this.PickTime) { this.Text.Text = dt.ToString(); } else if (this.PickDate) { this.Text.Text = dt.ToLongDateString(); } else //time { this.Text.Text = dt.ToLongTimeString(); } }
public static string FormatDateTimeLong(System.DateTime Expression) { return Expression.ToLongDateString() + " " + Expression.ToLongTimeString(); }