我需要使用devexpress DateEdit控件显示日期和时间。这可以通过为DateEdit Control设置Mask来实现。所以,目前我从当前的线程UI文化中采用了DateTime模式,并将其设置为DevExpress DateEdit控件的EditMask属性。
这里的问题是,我还需要向用户显示毫秒数。所有现有文化在DateTime模式中都没有毫秒。因此,我需要将毫秒字段(“fff”)添加到所选文化的DateTime模式,并将其设置为DateEdit控件EditMask属性。
我当前的代码块如下所示,
var dateEdit = new DateEdit();
dateEdit.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
dateEdit.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
CultureInfo currentUiCulture = Thread.CurrentThread.CurrentUICulture;
string editMask = currentUiCulture.DateTimeFormat.GeneralLongTimePattern;
dateEdit.Properties.EditMask = editMask;
以下是一些文化的DateTime模式和预期模式,
Culture DateTime Pattern Expected DateTime Pattern
----------------------------------------------------------------
{en-US} "M/d/yyyy h:mm:ss tt" "M/d/yyyy h:mm:ss.fff tt"
{th-TH} "d/M/yyyy H:mm:ss" "d/M/yyyy H:mm:ss.fff"
{sv-SE} "yyyy-MM-dd HH:mm:ss" "yyyy-MM-dd HH:mm:ss.fff"
我怎样才能做到这一点?
答案 0 :(得分:3)
试试这个:
// Append millisecond pattern to current culture's full date time pattern
string fullPattern = DateTimeFormatInfo.CurrentInfo.FullDateTimePattern;
fullPattern = Regex.Replace(fullPattern, "(:ss|:s)", "$1.fff");
来源:MSDN