Classic ASP - Display List of Timezones using powershell

心不动则不痛 提交于 2019-12-11 16:13:03

问题


Is there anyway to display system timezone using powershell GET-Timezone -ListAvailble. My requirements is to display this in a dropdownlist in an ASP page. Using .net com is not an option for me now, and even SQL server sys.time_zone_info.


回答1:


You could use Shell.Exec to call the powershell command and read from the standard output.

The powershell part is from Lee_Dailey's answer

<%
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>"

%>



回答2:


Get-TimeZone

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

If you run it without parameters it gives the current timezone on the host computer.

Example output:

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



回答3:


if all you want is the offset/name for each timezone known to the current system, this will give that list ...

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

as much as some may object, that is powershell. [grin]



来源:https://stackoverflow.com/questions/53717090/classic-asp-display-list-of-timezones-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!