Skip to main content
 首页 » 编程设计

c#之webservice DateTime 意外值

2024年01月28日20qq78292959

当我使用 system.datetime 作为我的数据成员时,它在我的数据 GridView 中返回了一种奇怪的格式。

我的数据成员看起来像这样:

    [DataMember(Name = "TimeAdded")] 
    public DateTime TimeAdded; 

我的 AddStudent 看起来像这样:

    public void AddStudent(Student student) 
    { 
        student.StudentID = (++eCount).ToString(); 
        student.TimeAdded = DateTime.Now; // not important more so the method to get the correct format 
        students.Add(student); 
    } 

我得到的输出是 2012-04-12T03:10:42.8138255+01:00 有没有办法解决这个问题?

请您参考如下方法:

我想你想要:

student.TimeAdded = DateTime.Now; 

现在您只是将空时间转换为本地时间。