How to Format a Date and Time with ToString in PowerShell
ToString turns a date into text in the format you choose: [DateTime]::UtcNow.ToString('r') returns the current UTC time in the RFC 1123 format, such as Thu, 03 Dec 2026 16:40:19 GMT. This guide formats the current time and a fixed date with a standard format and with patterns of your own, with real output from PowerShell 7.6.10.
A date in PowerShell is a DateTime object, not text, and its ToString method returns it as text. The DateTime.ToString page describes the call with a format: "Converts the value of the current DateTime object to its equivalent string representation using the specified format and the formatting conventions of the current culture."
Syntax
<date>.ToString('<format>')
[DateTime]::UtcNow.ToString('<format>')
| Part | What it means |
|---|---|
<date> | A date and time, such as a variable that holds one |
.ToString(...) | The method that returns the date as text. The parentheses are required |
'<format>' | The format, in quotes: one letter for a standard format, such as r, or a pattern of letters for a format of your own, such as yyyy-MM-dd |
[DateTime]::UtcNow | The current date and time in UTC |
How the two kinds of format are told apart, from the Standard date and time format strings page: "Any date and time format string that contains more than one character, including white space, is interpreted as a custom date and time format string."
The Example
The example turns the current UTC time into text, then formats one fixed date and time, 3 December 2026 at 14:30, in several ways. The commands only read the clock and make text, so they change nothing on your computer. They run in the PowerShell 7.6.10 console on a Mac.
Prerequisites
- PowerShell 7. This guide uses PowerShell 7.6.10:
$PSVersionTable.PSVersion.ToString()printed7.6.10.
Step 1: Get the Current UTC Time
[DateTime]::UtcNow
Thursday, December 3, 2026 4:40:17 PM
[DateTime] names the date type that PowerShell uses, from .NET, and ::UtcNow reads its UtcNow property. The DateTime.UtcNow page: "Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC)."
The console showed the date in a long, readable form, but the value is still a date, not text. The Get-Date page: "The default formats for the output of DateTime objects are long-date and long-time formats for the currently selected locale."
Step 2: Turn the Current Time into RFC 1123 Text
[DateTime]::UtcNow.ToString('r')
Thu, 03 Dec 2026 16:40:19 GMT

ToString('r') returned the time as text: the short day name, the day, the short month name, the year, the time on a 24-hour clock, and GMT. 16:40:19 is 4:40 PM, two seconds after the reading in Step 1, because each command read the clock when it ran.
r is a standard format: one letter that stands for the pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT'. The Standard date and time format strings page: "When this standard format specifier is used, the formatting or parsing operation always uses the invariant culture." The FAQ below shows r giving the same text with German settings.
Step 3: Format a Fixed Date Your Own Way
$d = Get-Date -Date '2026-12-03 14:30:00'
$d.ToString('r')
$d.ToString('yyyy-MM-dd')
$d.ToString('dd MMM yyyy, HH:mm')

Thu, 03 Dec 2026 14:30:00 GMT
2026-12-03
03 Dec 2026, 14:30
The first line made a date from the text and saved it in $d, without printing anything. The Get-Date page on -Date: "Specifies a date and time. Time is optional and if not specified, returns 00:00:00." A fixed date gives the same text every time, so the results are easy to compare.
The last two commands use custom formats: patterns of letters you write yourself. The Custom date and time format strings page: "A custom format string consists of one or more custom date and time format specifiers." Each specifier prints one part of the date:
| Specifier | Printed here | Meaning |
|---|---|---|
yyyy | 2026 | The year, as four digits |
MM | 12 | The month, as a number |
MMM | Dec | The month's short name |
dd | 03 | The day of the month, with a leading zero |
HH | 14 | The hour, on a 24-hour clock |
mm | 30 | The minutes |
Everything else in a pattern, such as the hyphens, the comma and the spaces, appeared as typed. The page's table says of any other character: "The character is copied to the result string unchanged."
Step 4: See What ToString Does Without a Format
$d.ToString()
(Get-Culture).Name
12/3/2026 2:30:00 PM
en-US
With no format, ToString used this computer's culture, en-US, the one Get-Culture returned: the month first, then the day, and a 12-hour clock. The DateTime.ToString page on this form: "Converts the value of the current DateTime object to its equivalent string representation using the formatting conventions of the current culture." A computer set to another culture prints another order, so pass a format whenever the text must always look the same.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
mm for the month: $d.ToString('yyyy-mm-dd') | 2026-30-03: the minutes, 30, took the month's place | Use capital MM for the month |
hh for a 24-hour time: $d.ToString('hh:mm') | 02:30 for a time of 14:30 | Use capital HH: $d.ToString('HH:mm') printed 14:30 |
No parentheses: $d.ToString | A list headed OverloadDefinitions, the ways to call ToString, instead of a date | Add the parentheses and the format: $d.ToString('r') |
Text instead of a date: '2026-12-03 14:30:00'.ToString('r') | MethodException: Cannot find an overload for "ToString" and the argument count: "1". | Make a date first: (Get-Date -Date '2026-12-03 14:30:00').ToString('r') printed Thu, 03 Dec 2026 14:30:00 GMT |
For the first two rows, the Custom date and time format strings page describes mm as "The minute, from 00 to 59." and hh as "The hour, using a 12-hour clock from 01 to 12."
FAQ
Why UtcNow and not the local time?
Because r doesn't convert the time it formats: it writes the time as it is and adds GMT. The Standard date and time format strings page: "Although the RFC 1123 standard expresses a time as Coordinated Universal Time (UTC), the formatting operation does not modify the value of the DateTime object that's being formatted." [DateTime]::UtcNow is already in UTC: [DateTime]::UtcNow.Kind printed Utc. The fixed date has no time zone, $d.Kind printed Unspecified, so r printed its 14:30 unchanged. For a local time, the page adds: "Therefore, you must convert the DateTime value to UTC by calling the DateTime.ToUniversalTime method before you perform the formatting operation."
Does r change with the computer's language?
No. With the settings for German, the D format changed and r didn't:
$de = [cultureinfo]'de-DE'
$d.ToString('D', $de)
$d.ToString('r', $de)
Donnerstag, 3. Dezember 2026
Thu, 03 Dec 2026 14:30:00 GMT
[cultureinfo]'de-DE' gets the settings for German as used in Germany, and the second argument hands them to ToString. The DateTime.ToString page on this form: "Converts the value of the current DateTime object to its equivalent string representation using the specified format and culture-specific format information."
Can Get-Date do the same?
Yes, with -Format: Get-Date -Date $d -Format 'yyyy-MM-dd' printed 2026-12-03, and Get-Date -AsUTC -Format r printed the current UTC time, Thu, 03 Dec 2026 16:41:18 GMT. The Get-Date page: "The Format parameter outputs a String object." And on -AsUTC: "Converts the date value to the equivalent time in UTC."
Where is the RFC 1123 format used?
In web requests. The Azure Storage page Representation of date/time values in headers calls it "the preferred format for HTTP/1.1 operations", and explains the GMT: "Both are represented in the Coordinated Universal Time (UTC), also known as Greenwich Mean Time."
Conclusion
[DateTime]::UtcNow.ToString('r') returned the current UTC time as RFC 1123 text, Thu, 03 Dec 2026 16:40:19 GMT. Give ToString one letter for a standard format or a pattern of your own such as yyyy-MM-dd, watch the case of MM and mm, HH and hh, and format a UTC time with r.
Additional Resources
- DateTime.ToString — every way to call
ToString, with and without a format. - Standard date and time format strings — the one-letter formats, including
r. - Custom date and time format strings — every specifier you can use in a pattern of your own.
- Get-Date — PowerShell's date command, with its Format and AsUTC parameters.
