问题
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