如何将DateTimePicker格式化为hh:mm:ss以及在mysql中节省时间的合适类型是什么?

时间:2021-07-27 16:23:28

I want to save the time in the format hh:mm:ss from the DateTimePicker to MySQL database, How to format the DateTimePicker into hh:mm:ss only without date and What is the appropriate type to save time in mysql?

我想将格式hh:mm:ss的时间从DateTimePicker保存到MySQL数据库,如何将DateTimePicker格式化为hh:mm:ss只有没有日期和什么是在mysql中节省时间的合适类型?

Regards & Thanks,

问候和谢谢,

Putri Diana

1 个解决方案

#1


2  

You can format it to show time by

您可以格式化它以显示时间

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "hh:mm:ss";
dateTimePicker1.ShowUpDown = true;

Get the value into a Timespan object in this way for processing in your code

以这种方式将值传入Timespan对象以便在代码中进行处理

TimeSpan ts1 = TimeSpan.Parse(dateTimePicker1.Text);

I think MySql has got a Time Datatype you could use that (Ahh Got this here)

我认为MySql有一个你可以使用的时间数据类型(啊,这里有这个)

#1


2  

You can format it to show time by

您可以格式化它以显示时间

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "hh:mm:ss";
dateTimePicker1.ShowUpDown = true;

Get the value into a Timespan object in this way for processing in your code

以这种方式将值传入Timespan对象以便在代码中进行处理

TimeSpan ts1 = TimeSpan.Parse(dateTimePicker1.Text);

I think MySql has got a Time Datatype you could use that (Ahh Got this here)

我认为MySql有一个你可以使用的时间数据类型(啊,这里有这个)