DateTime PIcker显示小时和分钟 [英] DateTime PIcker to Display hour and min
本文介绍了DateTime PIcker显示小时和分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在使用日期时间选择器以hr和MIN
显示时间
我希望datetime选择器以这样的方式显示小时和时间:小时应增加1,最小应增加15(例如:0,15,30,45)
到目前为止,我知道了
Hi
I am Using Date time picker to display the time in hr AND MIN
I want the datetime picker to show the hour and time in such a way that hour should increment by 1 and min should increment by 15(eg: 0,15,30,45)
This is so far i got
DTPendtime.CustomFormat = "HH:mm"//where DTPendtime is datetime picker
DTPendtime.Format = DateTimePickerFormat.Custom
DTPendtime.ShowUpDown = True
Private Sub DTPendtime_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DTPendtime.ValueChanged
txtendtime.Text = DTPendtime.Text
End Sub
推荐答案
这是VB版本:
This the VB version:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim d As DateTime = DateTimePicker1.Value
Dim i As Integer = d.Minute Mod 15
If (i > 0) Then
DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(15 - i).AddSeconds(-d.Second)
End If
End Sub
尝试如下操作:
Try something like this:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
var diff = dateTimePicker1.Value.TimeOfDay.Minutes % 15;
if (diff != 0)
{
dateTimePicker1.Value = dateTimePicker1.Value.AddMinutes(15 - diff);
}
}
感谢您的回复dmageiras811
您的帖子真的很有帮助
Thanks For the Reply dmageiras811
Your post was really helpful
这篇关于DateTime PIcker显示小时和分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文