如何在c#中将文本框日期更改为ddmmyyy格式 [英] how to change the textbox date to ddmmyyy format in c#

查看:152
本文介绍了如何在c#中将文本框日期更改为ddmmyyy格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证c中的textboxdate和gridview行日期#



我的代码如下



i want to validate the textboxdate and gridview row date in c#

My code as follows

DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue);
for (int i = 0; i < GvSch.Rows.Count; i++)
{
  if (selectedfromdate == Convert.ToDateTime(rows.Cells[0].Text.ToString().Trim()))
  {
    Lblerr.Text = "selected date and excel sheet should be same";
    return;
  }
}





当我调试和检查时

在selectfrom日期值是9月2日上午12:00:00

rows.cells [0] .text.tostring(),trim()值是1-Sep-14



i想要改变所选日期的格式是1-sep-14格式。



与gridview日期格式相同1-Sep -14。



我怎样才能在asp.net中使用c#。



When i debug and check
In selectedfrom date value is 9/2/2014 12:00:00 AM
rows.cells[0].text.tostring(),trim() value is 1-Sep-14

i want to change the format of selectedfrom date is 1-sep-14 format.

like same as gridview date format 1-Sep-14.

for that how can i do in asp.net using c#.

推荐答案

转换两种比较日期都是一种格式。



更多关于日期格式http://www.csharp-examples.net/string-format-datetime/ [ ^ ]



Convert Both the comparing dates to one format.

more about date formats http://www.csharp-examples.net/string-format-datetime/[^]

DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue).ToString("dd-MMM-yy");

for (int i = 0; i < GvSch.Rows.Count; i++)
{
  if (selectedfromdate == Convert.ToDateTime(rows.Cells[0].Text.ToString("dd-MMM-yy").Trim()))
  {
    //do your code here.

  }
}


DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue).ToString("dd-MMM-yyyy");

for (int i = 0; i < GvSch.Rows.Count; i++)
{
  if (selectedfromdate == Convert.ToDateTime(rows.Cells[0].Text.ToString().Trim()))
  {
    Lblerr.Text = "selected date and excel sheet should be same";
    return;
  }
}


这篇关于如何在c#中将文本框日期更改为ddmmyyy格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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