第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在ASP.NET中獲取客戶端日期和時(shí)間?

如何在ASP.NET中獲取客戶端日期和時(shí)間?

www說(shuō) 2019-12-02 13:15:09
我使用DateTime.Now服務(wù)器時(shí)會(huì)得到日期和時(shí)間。有什么方法可以在ASP.NET中獲取客戶端日期和時(shí)間?
查看完整描述

3 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

我喜歡使用瀏覽器/系統(tǒng)時(shí)間和時(shí)區(qū)或讓他們選擇其時(shí)區(qū)的想法。在過(guò)去的項(xiàng)目中,我使用了以下內(nèi)容:


<script language="javascript">

function checkClientTimeZone()

{

    // Set the client time zone

    var dt = new Date();

    SetCookieCrumb("ClientDateTime", dt.toString());


    var tz = -dt.getTimezoneOffset();

    SetCookieCrumb("ClientTimeZone", tz.toString());


    // Expire in one year

    dt.setYear(dt.getYear() + 1);

    SetCookieCrumb("expires", dt.toUTCString());

}


// Attach to the document onload event

checkClientTimeZone();

</script>

然后在服務(wù)器上:


/// <summary>

/// Returns the client (if available in cookie) or server timezone.

/// </summary>

public static int GetTimeZoneOffset(HttpRequest Request)

{

    // Default to the server time zone

    TimeZone tz = TimeZone.CurrentTimeZone;

    TimeSpan ts = tz.GetUtcOffset(DateTime.Now);

    int result = (int) ts.TotalMinutes;

    // Then check for client time zone (minutes) in a cookie

    HttpCookie cookie = Request.Cookies["ClientTimeZone"];

    if (cookie != null)

    {

        int clientTimeZone;

        if (Int32.TryParse(cookie.Value, out clientTimeZone))

            result = clientTimeZone;

    }

    return result;

}

或者,您可以將其作為URL參數(shù)傳遞并在Page_Load中進(jìn)行處理:


http://host/page.aspx?tz=-360

請(qǐng)記住要使用分鐘,因?yàn)椴⒎撬袝r(shí)區(qū)都是整個(gè)小時(shí)。


查看完整回答
反對(duì) 回復(fù) 2019-12-02
  • 3 回答
  • 0 關(guān)注
  • 912 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)