c# - DevExpress 控件 EditMask 属性的带毫秒的 DateTime 格式

标签 c# devexpress

我需要使用 devexpress DateEdit 控件显示日期和时间。这可以通过为 DateEdit 控件设置 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;

下面是一些文化的日期时间模式和预期的模式,

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"

我怎样才能做到这一点?

最佳答案

试试这个:

// 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

关于c# - DevExpress 控件 EditMask 属性的带毫秒的 DateTime 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16462282/

相关文章:

c# - XML 序列化和空集合

c# - IEquatable 可以比较具有其他自定义对象的列表属性的自定义对象吗?

c# - 哪种方法限制大 blob 的内存使用 : SqlReader. GetBytes 或 SqlReader.GetStream?

C# DynamoDB 复杂类型 IList<T> 转换器

javascript - 如何调用外部javascript函数到ClientSideEvents.Click事件?

c# - 如何在不移动按钮的情况下在中间设置 XtraForm 标题文本?

c# - 用于 asp.net core 的 NLog 不过滤 Microsoft 日志

c# - 如何引用未使用的参数?

c# - 右键单击 DevExpress Xtra GridControl 列标题时如何删除菜单选项?

javascript - 如何在ascx中获取客户端id devexpress控制