0

JavaScript を使用して C# の dateTime フィールドをフォーマットし、グリッドに dd-mon-yyyy として表示します。しかし、C# の datetime を javascript 変数に渡すと、システムのタイムゾーンに基づいて変換されます。つまり、Fri Aug 31 2012 06:59:14Fri Aug 31 2012 11:29:14 GMT+0530 (インド標準時)に変換されます。それを避ける方法は?私は Telerik グリッドを使用しているため、javascript を使用する以外にオプションはありません。

4

1 に答える 1

1

javascriptが同じになるすべての変換にjavascriptを使用しているため、c#またはその他のものを使用している場合、変更はありません..

もう1つの解決策は、C#の日付と時刻を文字列に変換し、javascriptでその日付文字列を日付に解析して、何が起こるかを確認することです。

タイムゾーンを変換するには、次のコードを確認してください

// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {

    // create Date object for current location
    // here you can pass your own date also
    d = new Date();

    // convert to msec
    // add local time zone offset 
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));

    // return time as a string
    return "The local time in " + city + " is " + nd.toLocaleString();

}

参照: http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329

于 2012-11-19T07:36:02.180 に答える