我如何设置标签或文本框或获取没有日期的时间 [英] How I do label or textbox set or get Just time without date

查看:82
本文介绍了我如何设置标签或文本框或获取没有日期的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1-如果我想在没有来自用户的日期获得时间为10:30 Pm而非2015年1月1日00:00:00

2-如果我想获得开始时间或结束过程并搜索两次之间的时间



如果开始时间是上午10:00 ---结束时间02:00 pm



用户将在开始和结束之间的01:00 pm搜索输入

1- if i want to make get just time without Date from user as 10:30 Pm not 1/1/2015 00:00:00
2- if I Want get time of Start or End Process and search about time Between that two times

if time of start 10:00 am --- time of End 02:00 pm

user will search enter 01:00 pm that between start & end

推荐答案

首先从文本框中获取文本并尝试把它解析为DateTime格式。

然后把一天中的时间作为一个字符串。



First get the text from the textbox and try to parse it into a DateTime format.
Then get the time of day as a string.

string date = string.Empty;

if (!string.IsNullOrWhiteSpace(textBox1.Text)) {
    DateTime timeDate = new DateTime(); 
    
    if (DateTime.TryParse(textBox1.Text, out timeDate)) {
        date = timeDate.TimeOfDay.ToString();
    }
}

if (!string.IsNullOrWhiteSpace(date)) {
    // do what is needed
}

这篇关于我如何设置标签或文本框或获取没有日期的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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