通过查询字符串传递C#DateTime [英] Passing a C# DateTime via the Query String
本文介绍了通过查询字符串传递C#DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C#DateTime对象。该对象包括日期和时间。我需要将此信息传递给基于REST的服务。我的问题是,如何格式化DateTime,以便可以通过查询字符串传递它,然后将其解析回服务器端的DateTime中?
DateTime startDate = GetStartDate();
字符串url = http://www.mydomain.com/myservice.svc/[startDateGoesHere]
WebRequest请求= HttpWebRequest.Create(url);
请求。BeginGetResponse (新的AsyncCallback(Service_Completed),请求);
谢谢,
解决方案
只需使用ToString()并传递格式,例如:startDate.ToString( yyyyMMddHHmmss)
I have a C# DateTime object. This object includes both the date and time. I need to pass this information to a REST-based service. My question is, how do I format the DateTime, such that I can pass it via the query string, and parse it back into a DateTime on the server-side?
DateTime startDate = GetStartDate();
string url = "http://www.mydomain.com/myservice.svc/[startDateGoesHere]
WebRequest request = HttpWebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(Service_Completed), request);
Thank you,
解决方案
Just use ToString() and pass a format e.g.: startDate.ToString("yyyyMMddHHmmss")
And parse it back by using DateTime.ParseExact()
这篇关于通过查询字符串传递C#DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文