DateTime选择器C#格式 [英] DateTime picker C# format

查看:182
本文介绍了DateTime选择器C#格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DateTime 选择器添加到列表的到达时间,我有2个问题:

I have a DateTime picker to add arrival time to a list, I have 2 questions about it:


  1. 如何显示日期,如 2012年1月12日而不是 12/01/12

  2. 如何让它显示日期之后的时间,但不显示当前时间,因为这是什么显示atm。

  1. How can I get it to show dates like 12-Jan-2012 Instead of 12/01/12?
  2. How can I get it to show the time after the date but not the current time, as thats what is shows atm.

我目前的代码不太高级:

My current code is not very advanced its just:

theVisit.ArrivalTime = DateTimePicker1.Value


推荐答案

日期和时间:

DateTimePicker1.Value.ToString("d-MMM-yyyy hh:mm:ss");

要覆盖默认的DateTimePicker设置,您可以执行以下操作:

To override the default DateTimePicker settings, you can do this:

DateTimePicker1.Format = DateTimePickerFormat.Custom;
DateTimePicker1.CustomFormat = "d-MMM-yyyy  hh:mm:ss";

您可以通过修改格式字符串来显示不同的时间,例如:

You can show a different time by modifying the format string, e.g.:

DateTimePicker1.CustomFormat = "d-MMM-yyyy 12:00:00";

甚至

DateTime otherTime = DateTime.Now;
DateTimePicker1.CustomFormat = "d-MMM-yyyy " + otherTime.ToString("hh:mm:ss");

这篇关于DateTime选择器C#格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆