【问题标题】:DateTime format with milliseconds for DevExpress control EditMask propertyDevExpress 控件 EditMask 属性的 DateTime 格式,以毫秒为单位
【发布时间】:2013-05-09 12:54:04
【问题描述】:

我需要使用 devexpress DateEdit 控件显示日期和时间。这可以通过设置 DateEdit 控件的掩码来实现。因此,目前我已从当前线程 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"

我怎样才能做到这一点?

【问题讨论】:

    标签: c# devexpress


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-08
      • 2011-08-22
      • 1970-01-01
      • 2019-02-24
      • 2015-09-16
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      相关资源
      最近更新 更多