# system's time zone offset, which will confuse ConvertTime() # Note the `z` here tells the ToString method to include the $time_to_convert = ((Get-Date).ToString('yyyy-MM-ddTHH:mm:ssz')) # This will NOT work, because the string contains the local time zone We will use a string here, because we will be specifying the input time zone using the variables we just created: # This will work
Next we need the date and time we would like to convert. We’ll assign both of these to variable that we can use later: # Assign India time zone info to a variable So, if we want to convert from a time zone different from the one our system is in, we need to do a bit more work… Converting Between Two Different Time Zonesįirst, we need time zone information for both the source and destination. Using this information, we can convert from the input time to whatever time zone we choose by using TimeZoneInfo.ConvertTimeBySystemTimeZoneId Method: ::ConvertTimeBySystemTimeZoneId( `ĬonvertTimeBySystemTimeZoneId uses the local system’s time zone to determine the input time zone, since the output object of Get-Date does not have the Kind property and the default is Unspecified. Here is an example: Id : India Standard TimeĭisplayName : (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi This will output a list of time zones as objects. Net TimeZoneInfo Class, as follows: ::GetSystemTimeZones( ) To list valid time zones, we can access the. In my first example, I used “Greenwich Standard Time”, but what about other time zones? And how did I know that “Greenwich Standard Time” was a valid time zone anyway? Next, you want to determine the name of the time zone you are converting that input time to. What if you want to use a different time then the current time though? Well, the solution is as simple as giving Get-Date the time you want to use: Get-Date " 00:00"įor more ways of getting dates and times, see my previous post on displaying different dates and times with PowerShell. We’ll call this the “input time” from now on. We are essentially providing two date and time objects - one to convert from, the other to convert to: ::ConvertTimeBySystemTimeZoneId( $convert_from, $to )īreaking it down, you first want to get the time to convert from, using the Get-Date command.
Where we have ‘Greenwich Standard Time’ here, you can put any time zone you wish and get the current time in that time zone (Note, too, that I have used the backtick (`) to split this into two lines in order to make it easier to read, which you do not have to do).
In a hurry? Here’s how to convert the current date and time from the local time zone to another one: ::ConvertTimeBySystemTimeZoneId( ` In this post, I’m going to show you how to do this really easily in PowerShell. If you work in a multinational organization like me or you have loved ones or friends who live in other parts of the country or world, then you have, no doubt, found yourself needing to convert time from one time zone to another. Convert Time for different World Time Zone