在asp.net中添加时间值 [英] adding time value in asp.net

查看:65
本文介绍了在asp.net中添加时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次在Web应用程序中添加时间值

i am new to adding time values in web application

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    string st;
    DateTime dt = new DateTime();
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox4.Text = dt.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = System.DateTime.Now.ToString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox2.Text = System.DateTime.Now.ToString();
        DateTime d1 = Convert.ToDateTime(TextBox1.Text);
        DateTime d2 = Convert.ToDateTime(TextBox2.Text);
        System.TimeSpan diff = d2.Subtract(d1);
        DateTime d3 = Convert.ToDateTime(TextBox4.Text);
        DateTime d4 = Convert.ToDateTime(diff);
        System.TimeSpan diff1 = d4.Add(d3);
        TextBox4.Text = diff1.ToString();
        TextBox3.Text = diff.ToString();
        TextBox1.Text = "";
        TextBox2.Text = "";

    }
}


在运行页面时,我得到错误为


while running the page i got error as

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for ''System.DateTime.Add(System.TimeSpan)'' has some invalid arguments

Source Error:

Line 31:         DateTime d3 = Convert.ToDateTime(TextBox4.Text);
Line 32:         DateTime d4 = Convert.ToDateTime(diff);
Line 33:         System.TimeSpan diff1 = d4.Add(d3);
Line 34:         TextBox4.Text = diff1.ToString();
Line 35:         TextBox3.Text = diff.ToString();


Source File: c:\Documents and Settings\JTS 2\My Documents\Visual Studio 2008\WebSites\WebSite8\Default.aspx.cs    Line: 33



请帮我


提前发短信
Dineshkumar R



pleas help me


tks in advance
Dineshkumar R

推荐答案

日期时间格式可能是问题.请检查此线程

[转换日期格式 [
Date Time format may be the issue.Check this thread

CS1502: The best overloaded method match for ''System.DateTime.Add (System.TimeSpan)'' hock sometime Invalid argument[^]

Converting the date formats[^]


Line 31:         DateTime d3 = Convert.ToDateTime(TextBox4.Text);
Line 32:         DateTime d4 = Convert.ToDateTime(diff);
Line 33:         System.TimeSpan diff1 = d4.Add(d3);// you cannot add datetime to a TimeSpan;
Line 34:         TextBox4.Text = diff1.ToString();
Line 35:         TextBox3.Text = diff.ToString();




您应该将日期时间转换为时间跨度,诸如此类.




you should convert datetime into timespan some thing like this.

TimeSpan t=new TimeSpan();
t.Add(TimeSpan.FromTicks(DateTime.Now.Ticks()));//instead here it should be your date.


这篇关于在asp.net中添加时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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