แก้ไข

แชร์ผ่าน


Set-TimeZone

Sets the system time zone to a specified time zone.

Syntax

Set-TimeZone
   [-Name] <String>
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-TimeZone
   -Id <String>
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-TimeZone
   [-InputObject] <TimeZoneInfo>
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

This cmdlet is only available on the Windows platform.

The Set-TimeZone cmdlet sets the system time zone to a specified time zone.

Examples

Example 1: Set the time zone by Id

This example sets the time zone on the local computer to UTC.

Set-TimeZone -Id "UTC"

Id                         : UTC
HasIanaId                  : True
DisplayName                : (UTC) Coordinated Universal Time
StandardName               : Coordinated Universal Time
DaylightName               : Coordinated Universal Time
BaseUtcOffset              : 00:00:00
SupportsDaylightSavingTime : False

Example 2: Set the time zone by name

This example sets the time zone on the local computer to UTC.

Set-TimeZone -Name 'Coordinated Universal Time' -PassThru

As we saw in the previous example, the Id and the Name of the Time Zone do not always match. The Name parameter must match the StandardName or DaylightName properties of the TimeZoneInfo object.

Note

The time zone names can vary based on the Culture settings in Windows. This example shows the values for a system set to en-US.

Example 3 - List all available time zones

A full list of Time Zone IDs can be obtained by running the following command:

Get-TimeZone -ListAvailable

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Id

Specifies the ID of the time zone that this cmdlet sets.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-InputObject

Specifies a TimeZoneInfo object to use as input.

Type:TimeZoneInfo
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

Specifies the name of the time zone that this cmdlet sets. A full list of Time Zone names can be obtained by running the following command: Get-TimeZone -ListAvailable.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

TimeZoneInfo

Outputs

None

By default, this cmdlet returns no output.

TimeZoneInfo

When you use the PassThru parameter, this cmdlet returns a TimeZoneInfo object.

Notes

PowerShell includes the following aliases for Set-TimeZone:

  • Windows:
    • stz

This cmdlet is only available on Windows platforms.