最佳答案
您可以通过扩展Sitecore.Shell.Applications.ContentEditor.DateTime
来覆盖默认时间格式。类,找到 TimePicker
在该控件内并更改 Format
属性(默认设置为 t
,这意味着将使用内容编辑器用户的标准区域设置)。老实说,我不认为任何 Sitecore 解决方案都应该建议更改此设置,但如果需要,这是可行的。
首先,创建继承自 Sitecore.Shell.Applications.ContentEditor.DateTime
的自定义类,例如:
namespace My.Assembly.Namespace.ContentEditor
{
public class CustomDateTime : Sitecore.Shell.Applications.ContentEditor.DateTime
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
TimePicker timePicker = FindTimePicker(this);
if (timePicker != null)
{
timePicker.Format = "HH:mm";
}
}
private TimePicker FindTimePicker(Control control)
{
if (control != null)
{
var timePicker = control as TimePicker;
if (timePicker != null)
{
return timePicker;
}
foreach (Control childControl in control.Controls)
{
if ((timePicker = FindTimePicker(childControl)) != null)
{
return timePicker;
}
}
}
return null;
}
}
}
现在在web.config
查找<controlSources>
标签,并在该标签内添加以下行:
<source mode="on" namespace="My.Assembly.Namespace.ContentEditor" assembly="My.Assembly" prefix="customcontent"/>
现在转到Sitecore Desktop,切换到core数据库,找到/sitecore/system/Field types/Simple Types/Datetime
Control
的项目和更改值字段至 customcontent:CustomDateTime
:
切换回主数据库并检查任何日期时间字段,例如:
关于Sitecore 在内容编辑器中以 24 小时格式显示时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32840706/