2012-07-05 37 views
1

下面是我的ASP(ASP.NET不)代碼:經典顯示IST(印度標準時間)ASP

<% 
days = day(now) 
    if len(days) <> 2 then 
     days = "0"&days 
    END IF 
    months = month(now) 
    if len(months) <> 2 then 
     months ="0"&months 
    end if 
    min = dateadd("n",2,now) 
    hr = dateadd("h",-5,now) 
    Hrs = hour(hr) 
    if len(Hrs) <> 2 then 
     Hrs ="0"&Hrs 
    end if 
    Mins = minute(min) 
    if len(Mins) <> 2 then 
     Mins ="0"&Mins 
    end if 
    Secs = second(now) 
    if len(Secs) <> 2 then 
     Secs ="0"&Secs 
    end if 
    datess = year(now)&"-"&months&"-"&days&"T"&Hrs&":"&Mins&":"&Secs 

    response.write(datess) %> 

輸出是服務器時間(服務器託管UK)。現在我想將其轉換爲IST(印度標準時間)。我如何在Classic ASP中做到這一點?

+0

邏輯說,你應該採用UTC時間,並根據時區爲UTC時間添加時間,例如我估計IST爲5:30小時。 – yogi

回答

0

您可以在當前英國時間上添加正確的小時數(GMT + 5:30)。

DateAdd("n",330,NOW()) --adds 5 1/2 hours to current time 

你需要一個功能,還允許這樣的事實印度標準時間不會以同樣的方式在英國確實實行夏令時間內做到這一點(在英國夏令時間)。因此,對於一年中的某些部分,您只能添加4個半小時。

實例功能:

<% 
offset = 330 '5 1/2 hours in minutes 

' tell us what date you want 
currentUkDateTime = NOW() 

' find first Sunday in April 
for i = 1 to 7 
    if weekday("4/" & i & "/" & year(d))=1 then 
     startDST = cdate("4/" & i & "/" & year(d)) 
    end if 
next 

' find last Sunday in October 
for i = 31 to 25 step -1 
    if weekday("10/" & i & "/" & year(d))=1 then 
     endDST = cdate("10/" & i & "/" & year(d)) 
    end if 
next 

' subtract hour from offset if within DST 
if cdate(od) >= startDST and cdate(od) < endDST then 
    offset = offset - 1 
end if 

currentISTDateTime = dateadd("n", offset, currentUkDateTime) 

Response.Write("Current = " & currentUkDateTime & "<Br>UTC = " & currentISTDateTime) 
%> 

(從classicasp.aspfaq.com幫助)

+0

當英國目前在BST時,你會怎麼測量? – AnthonyWJones

+0

查找4月的第一個星期日,並在10月的上個星期天查找,然後確定請求的日期時間是否在此期間內,並根據情況加/減1小時 –

1

ASP VBScript不明白時區的概念,只是當前的服務器是什麼時候了。 JScript ASP的確如此,幸運的是,您可以在ASP中混合搭配您的腳本語言。

這將使用JScript中獲得UTC日期和時間爲格式的VBScript就可以理解和操作上:

<script language="javascript" runat="server"> 

    var od = new Date(); 
    var nd = od; 
    var s = nd.getUTCDate() + "/"; 
    s += (nd.getUTCMonth() + 1) + "/"; 
    s += nd.getUTCFullYear() + " "; 
    s += (nd.getUTCHours()) + ":"; 
    s += nd.getUTCMinutes() + ":"; 
    s += nd.getUTCSeconds(); 
    datUTC = s; 

</script> 
<% 

Response.Write(FormatDateTime(datUTC, 3)) 

%> 

一旦你有UTC,那麼你可以申請自己的規則將其轉換成IST可預測。

0

在ASP中你有一些所謂的語言環境中,檢查: http://support.microsoft.com/kb/229690

但是......一定要走這條路,我給你去檢查,如果你是幸福的: - 貨幣 - 日期時間 - 和LAST但不租賃小數分隔符....在某些LOCALES分隔符是一個逗號(而不是美國,它是一個。),你可能最終與SELECT * FROM文章WHERE價格> 3,14 - >參數提供的大錯誤(LOCALE可能會將PI(3.14)更改爲3,14,這可以避免,但是...經典ASP中的國際化相當「簡單」...