约会游乐场失去一天:SWIFT

时间:2015-05-07 01:22:51

标签: swift timezone nsdate nsdateformatter

我尝试使用日期,将它们保存为字符串,然后将它们返回日期。我的输出失去了一天。请参阅下面的游乐场代码:

date = May 7, 2015, 9:16 AM 
dateString = "Thursday, May 7, 2015" (perfect) 
let finalDate shows: "May 7, 2015, 12:00 AM" (almost perfect except the time) 
println(finalDate) reveals : 2015-05-06 16:00:00 +0000 

这是当前的输出:

public static QHttpResponse Execute(QHttpRequest request)
{
    //Setup the request
    HttpWebRequest webrequest = (HttpWebRequest) WebRequest.Create(request.GetFinalUrl());
    webrequest.AllowAutoRedirect = request.IsAllowRedirects;
    webrequest.Method = request.Method;
    webrequest.Accept = "application/json, text/javascript;q=0.9, */*;q=0.5";
    webrequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    //request.Host is set automatically
    webrequest.UserAgent = request.UserAgent;
    if (!String.IsNullOrEmpty(request.Referrer))
        webrequest.Referer = request.Referrer;
    webrequest.Timeout = 50000;
    webrequest.KeepAlive = false;
    webrequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate);
    webrequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
    if (request.IsAjax)
    {
        webrequest.Headers.Add("X-Request", "JSON");
        webrequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
        webrequest.Headers.Add("X-Prototype-Version", "1.7");
    }

    // Cookies
    webrequest.CookieContainer = request.Cookies;

    // Write the data to the body for POST and other methods
    if (request.IsMethodPost())
    {
        byte[] dataBytes = Encoding.UTF8.GetBytes(request.GetDataParamString());
        webrequest.ContentLength = dataBytes.Length;

        using (Stream requestStream = webrequest.GetRequestStream())
            requestStream.Write(dataBytes, 0, dataBytes.Length);
    }

    // Get the response
    HttpWebResponse webresponse;
    try
    {
        webresponse = webrequest.GetResponse() as HttpWebResponse;
    }
    catch (WebException wex)
    {
        if(request.IsBypassError)
            webresponse = wex.Response as HttpWebResponse;
        else
            throw;
    }

    // Read to QHttpResponse object
    QHttpResponse response = new QHttpResponse();
    response.StatusCode = webresponse.StatusCode;
    response.NewCookies = webresponse.Cookies;
    using (Stream responseStream = webresponse.GetResponseStream())
        using (StreamReader reader = new StreamReader(responseStream))
            response.Reply = reader.ReadToEnd();

    webresponse.Close();

    return response;
}

我已经四处搜索并认为这是时区修改?我不确定。我会更多地玩它,看它是否适合我的需要。知道为什么println执行时输出会有所不同而只是计算?

0 个答案:

没有答案