1
클라이언트의 시간을 알아야합니다. 내 행동 과정은 쿠키에서 오프셋을 유지 한 다음 계산하는 것입니다. 내 문제는 첫 번째 페이지를로드하는 중에도 쿠키를 삽입해야한다는 것입니다. 나는 많은 방법이 있지만 아무도 필요에 대답하지 않는다는 것을 압니다. 첫 페이지가로드되기 전에 로컬 시간을 사용해야합니다. 그래서 JavaScript를 사용할 수 없습니다.자바 스크립트 및 포스트를 사용하여 클라이언트 시간을 받으십시오.
사용자를 게시물의 클라이언트로 다시 보내고 쿠키를 넣은 다음 서버로 돌려 보려고했지만 쿠키가 없기 때문에 문제가됩니다. 여기
는 기능입니다 :public static DateTime? GetClientTime()
{
HttpRequest Request = HttpContext.Current.Request;
if (Request.Cookies["DynoOffset"] != null)
{
string strOffset = Request.Cookies["DynoOffset"].Value;
int offset = int.Parse(strOffset);
TimeZone localZone = TimeZone.CurrentTimeZone;
DateTime currentDate = DateTime.Now;
DateTime CreationDate = localZone.ToUniversalTime(currentDate).AddMinutes(-offset);
return CreationDate;
}
else
{
StoreClientTime();
return null;
}
}
public static DateTime? StoreClientTime()
{
var Context = HttpContext.Current;
var Session = Context.Session;
var Response = Context.Response;
var Request = Context.Request;
// if the local time is not saved yet in Session and the request has not posted the localTime
if (Request.Cookies["DynoOffset"] == null && String.IsNullOrEmpty(Request.Params["localTime"]))
{
// then clear the content and write some html a javascript code which submit the local time
Response.ClearContent();
Response.Write("<form id='local' method='post' name='local'>" +
"<script src=\"/Js/jquery-1.7.1.min.js\" type=\"text/javascript\"></script>" +
"<script src=\"/Js/JqueryUI/jquery.cookie.js\" type=\"text/javascript\"></script>" +
"<script type=\"text/javascript\">" +
"$.cookie(\"DynoOffset\", new Date().getTimezoneOffset(), { expires: 150 });" +
"$(\"#local\").submit()" +
"</script>" +
"</form>");
//
Response.Flush();
// end the response so PageLoad, PagePreRender etc won't be executed
Response.End();
return null;
}
else
{
return GetClientTime().Value;
}
}
내가 오프셋 calture을 기반으로 찾을 생각,하지만 난 그것을하는 방법을 모르겠어요.
실제 문제는 "Google에 문제가 있습니까?"또는 다른 것이 있습니까? 그냥 모든 날짜를 UTC로 보내고 JavaScript로 포맷하는 것이 더 쉽습니다. –
"PreLoad"페이지에서이 메소드를 호출 할 수 있습니다.이 도움이 될 수 있기를 바랍니다 ... –
"Preload ...." 요청 처리기 내에서 동일한 작업을 수행 할 수 있습니다. –