C# WinForms DateTimePicker 自定义格式
我的表单上有一个 DateTimePicker
。我希望部分格式包含“今天”、“明天”等适当的内容。我有一个简单的实现来计算值(并且还有更好的实现这里),但我想采用该实现并将值直接放入 DateTimePicker
的 CustomFormat
属性中。
例如,给定以下格式:
dateTimePicker.CustomFormat = "dd MMM yyyy (YTT) HH:mm";
要在 2011 年 4 月 16 日 12:00 运行时生成以下显示:
"16 Apr 2011 (today) 12:00"
我希望这涉及构建 IFormatProvider
/ICustomFormatter
实现并hacking自定义CurrentCulture
来使用它。
非常感谢。
I have a DateTimePicker
on my form. I'd like part of the format to include "today", "tomorrow" etc as appropriate. I've got a simple implementation to work out the value (and there are much better ones here) but I'd like to take that implementation and put the value directly into the CustomFormat
property of the DateTimePicker
.
For example, given the following format:
dateTimePicker.CustomFormat = "dd MMM yyyy (YTT) HH:mm";
To produce the following display at runtime on 16th April 2011 at 12:00:
"16 Apr 2011 (today) 12:00"
I expect this is something involving building a IFormatProvider
/ICustomFormatter
implementation and hacking customising the CurrentCulture
to use it.
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在自定义日期格式字符串中的静态文本周围使用
'
。Use
'
around the static text in a custom date format string.