在文本框中显示月份号 [英] Display month number in text box

查看:100
本文介绍了在文本框中显示月份号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个服务开始日期并选择日期.用户将从日期时间选择器中选择日期.如果选择的日期大于服务开始日期,则它将显示月份号,例如,如果服务开始 date = 10/10/2011 并选择 date = 01/12/2011 ,则它将在文本框中显示2;如果选择 date = 9/9/2011 ,则将显示 -1 在文本框中.这是我的代码

Hi All,

I have a service commencement date and select date.Here user will select the date from date time picker.If selected date is greater than service comencement date then it will display the month number e.g if service commencement date =10/10/2011 and selected date=01/12/2011 then it will show 2 in textbox or if selected date=9/9/2011 then it will display -1 in textbox. Here is my code

DateTime dService= frmVwPersuit.dServiceCommDate;
           DateTime date = this.dateTimePicker1.Value;

           if (DateTime.Compare(dService, date) > 0)
           {
               this.txtMnth.Text = date.ToString("MM");
           }
           else
           {
               this.txtMnth.Text = date.ToString("-MM");
           }

推荐答案

int difference = date.Month - dService.Month;
this.txtMnth.Text = String.Format("{0:D2}", difference);


尝试一下..

try this..

DateTime dService= frmVwPersuit.dServiceCommDate;
            DateTime date = this.dateTimePicker1.Value;
 
            if (DateTime.Compare(dService, date) > 0)
            {
                this.txtMnth.Text = date.Month.ToString();
            }
            else
            {
                this.txtMnth.Text = date.Month.ToString();

            }


DateTime dService= frmVwPersuit.dServiceCommDate;
DateTime date = this.dateTimePicker1.Value;

this.txtMnth.Text = DateTime.Compare(dService, date) > 0 : date.Month.ToString() ? string.Format("-{0}",date.Month.ToString());



希望这会起作用.

谢谢
-amit



hope this will work.

thanks
-amit


这篇关于在文本框中显示月份号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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