经典 ASP - 使用 powershell 显示时区列表

Classic ASP - Display List of Timezones using powershell

是否可以使用 powershell GET-Timezone -ListAvailble 显示系统时区。我的要求是在 ASP 页面的下拉列表中显示它。使用 .net com 现在对我来说不是一个选择,甚至 SQL 服务器 sys.time_zone_info.

如果您想要的只是当前系统已知的每个时区的 offset/name,这将给出该列表...

[System.TimeZoneInfo]::GetSystemTimeZones().DisplayName

尽管有些人可能反对,但 powershell。 [咧嘴一笑]

Get-TimeZone

Gets the current time zone or a list of available time zones.

如果你 运行 它没有参数,它会给出主机上的当前时区。

示例输出:

Id                         : GMT Standard Time
DisplayName                : (UTC+00:00) Dublin, Edinburgh, Lisbon, London
StandardName               : GMT Standard Time
DaylightName               : GMT Daylight Time
BaseUtcOffset              : 00:00:00
SupportsDaylightSavingTime : True

您可以使用 Shell.Exec 调用 powershell 命令并从标准输出中读取。

powershell 部分来自

<%
Set objShell = server.CreateObject("WScript.Shell")
Set objExec = objShell.Exec("cmd /c powershell [System.TimeZoneInfo]::GetSystemTimeZones().DisplayName")
Set objStdOut = objExec.StdOut


Response.write "<select name=""Timezones"">"

While Not objStdOut.AtEndOfStream
   Response.write "<option>" & objStdOut.ReadLine & "</option>"
Wend

Response.write "</select>"

%>