【问题标题】:got error on datetime while using JsonServices in asp.net and android在 asp.net 和 android 中使用 JsonServices 时出现日期时间错误
【发布时间】:2016-08-16 00:45:10
【问题描述】:

我们正在做一个应用程序,它使用 jsonservice(webservice/RESTfull webservice) 作为后端数据处理过程和 Andriod 作为前端..

public DataTable retrv(string id)
{
    check();
    int ID = Convert.ToInt32(id.ToString());
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "select * from RECVSSMS where Refid='" + ID + "'";
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);         
    return dt;
}

在使用 Android Studio 中的 jsonservice 使用此代码时,我们得到了除 Date_Time 之外的所有记录格式。

我们有这样的记录:

I/System.out:@@@@@@@@@@@@@@@@@@@@@@{"Value":[{"Date_time":"2016-04-22T02:01 :15","status":"1","Message":"测试消息回复自动","FromID":"+919566003138","Refid":24}],"Successful":true}

这里的错误很明显:Date_time":"2016-04-22T02:01:15"

出现字母“T”且日期格式不正确

这是数据库字段:

Refid int 
FromID varchar(13)
Message varchar(60)
status varchar(5)
Date_Time datetime

【问题讨论】:

    标签: c# android asp.net json


    【解决方案1】:

    这不是错误,它是 sql 提供的日期时间格式之一,请使用以下格式代码获取所需的日期

    http://www.w3schools.com/sql/func_convert.asp

    【讨论】:

    • 但我刚刚在 asp.net webform 中使用 gridview 进行了测试。它显示了正确的格式...但是当使用 android studio 中的 web 服务时,它会改变格式,,
    • @Abdu .Net 可以理解 sql 日期,当您转换为 json 时,您应该将其转换为 json 日期格式 /\date() 或您想要的方式
    猜你喜欢
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    • 2014-03-24
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多