[英]Android post request for datetime to SQL Server
I have a web service to insert a new user to table users in SQL Server 2014. All the information gets inserted except the time, it is inserted as null. 我有一个Web服务,可在SQL Server 2014中向表用户插入新用户。除时间外,所有信息均已插入,并且将其插入为null。
Here is where I send data in Android 这是我在Android中发送数据的地方
jsonBody.put("nickname",nickname.getText().toString().trim());
jsonBody.put("firstname", firstname);
jsonBody.put("lastname",lastname);
jsonBody.put("created on", Calendar.getInstance(TimeZone.getDefault()));
jsonBody.put("phonenumber", phonenumber.getText().toString().trim());
All of them are sent correctly except for the time. 除时间以外,所有其他均正确发送。 By the way I defined the data type of the date as datetime in the SQL database.
顺便说一下,我在SQL数据库中将日期的数据类型定义为datetime。
Any help would be appreciated. 任何帮助,将不胜感激。
I got the right answer. 我得到正确的答案。
Just replace 只需更换
Calendar.getInstance(TimeZone.getDefault()
with 与
DateFormat.getDateTimeInstance().format(new Date()).toString()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.