私の剣道グリッドでは、サーバーから日時を受け取ります。クライアント側では、この時間がクライアントのタイムゾーンに変更されて表示されます。サーバーからクライアントに同じ時間を表示するにはどうすればよいですか。
以下は、日時をバインドするための私の剣道コードです。
columns.Bound(p => p.CreateDate).Format("{0:dd/MM/yyyy hh:mm:ss}").Sortable(true).Width(180);
私の剣道グリッドでは、サーバーから日時を受け取ります。クライアント側では、この時間がクライアントのタイムゾーンに変更されて表示されます。サーバーからクライアントに同じ時間を表示するにはどうすればよいですか。
以下は、日時をバインドするための私の剣道コードです。
columns.Bound(p => p.CreateDate).Format("{0:dd/MM/yyyy hh:mm:ss}").Sortable(true).Width(180);
サーバーからの応答が返されたときにクライアントで日付が作成されるため、日付は常にブラウザーのタイムゾーンに応じたオフセットで作成されます
これはあなたを助けるでしょう:
http://www.kendoui.com/code-library/mvc/grid/using-utc-time-on-both-client-and-server-sides.aspx
もう 1 つのオプションは、カスタムJsonResult
を使用して日付をISO
形式に変換することです。
public class IsoDateJsonResult : JsonResult
{
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
HttpResponseBase response = context.HttpContext.Response;
if (!String.IsNullOrEmpty(ContentType))
{
response.ContentType = ContentType;
}
else
{
response.ContentType = "application/json";
}
if (ContentEncoding != null)
{
response.ContentEncoding = ContentEncoding;
}
if (Data != null)
{
var isoConvert = new IsoDateTimeConverter();
response.Write(JsonConvert.SerializeObject(Data, isoConvert));
}
}
次に、メソッドをの代わりにController
returnに変更します。IsoDateJsonResult
ActionResult/JsonResult