订阅拖曳日期时间的问题 [英] problem during subscribe tow datetime

查看:78
本文介绍了订阅拖曳日期时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图订阅拖曳日期时间

I tried to subscribe tow datetime

Publics.JSS_FT = null;
TimeSpan DEF = System.Convert.ToDateTime(dateTimePicker2.Text) - JCM_NOW_DT;
label11.Text = DEF.ToString();
Publics.JSS_FT = label11.Text;



但是我得到了这个结果: 735140-15:25:55

DEF 中的值是好的但是 label11.Text


如何保持格式HH:mm:ss



谢谢


but i get this result : 735140-15:25:55
during debuging : the value in DEF is good but the error here in label11.Text

how i can keep the format HH:mm:ss

thank you

推荐答案

ToString 调用中使用正确的格式模板,例如:

Use a proper format template in your ToString call, such as:
label11.Text = DEF.ToString("hh\\:mm\\:ss");



您的代码使用文档 [ ^ ],这是最好先检查的地方。



[edit]

添加转义字符以保护冒号。

[\ edit]


Your code uses the default as described in the documentation[^], which is always the best place to check first.

[edit]
Added escape character to protect the colons.
[\edit]


谢谢。我已经解决了这个问题..



我认为你们两个都已经是真的,但到目前为止我还不知道错误原因



i创建一个新表单并重写代码。结果是00:15:12是好的



代码:



Thank you. i have solved the problem ..

I think that both of you are already true, but I did not know cause of the error so far

i Created a new form and rewrite the codes . the result is 00:15:12 is ok

the code:

Publics.JSS_FT = null;
                            TimeSpan DEF = System.Convert.ToDateTime(dateTimePicker2.Text) - JCM_NOW_DT;
                            //  label11.Text = string.Format("{0:00}:{1:00}:{2:00}", DEF.Hours, DEF.Minutes, DEF.Seconds); // this is ok

                            // Or if by HH:mm:ss you mean TotalHours
                          //  label11.Text = string.Format("{0:00}:{1:00}:{2:00}", DEF.TotalHours, DEF.Minutes, DEF.Seconds); // this is ok
                            label11.Text = DEF.ToString(); // this is ok
 // label11.Text = DEF.ToString("hh:mm:ss"); // appear error  Input string was not in a correct format.
                            Publics.JSS_FT = label11.Text;





thanks



thanks


我知道格式化字符串的最简单方法是使用string.Format方法。但令人惊讶的是,DEF.ToString(); call(这是一个TimeSpan对象)确实返回格式hh:mm:ss,所以不确定问题是否存在。



The easiest way I know of formatting a string is using the string.Format method. But surprisingly, the DEF.ToString(); call (which is a TimeSpan object) does return the format hh:mm:ss, so not sure the issue is there.

Publics.JSS_FT = null;
TimeSpan DEF = System.Convert.ToDateTime(dateTimePicker2.Text) - JCM_NOW_DT;
label11.Text = string.Format("{0:00}:{1:00}:{2:00}", DEF.Hours, DEF.Minutes, DEF.Seconds);

// Or if by HH:mm:ss you mean TotalHours
label11.Text = string.Format("{0:00}:{1:00}:{2:00}", DEF.TotalHours, DEF.Minutes, DEF.Seconds);

Publics.JSS_FT = label11.Text;


这篇关于订阅拖曳日期时间的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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