Skip to Content
Windows PowerShell Pocket Reference, 2nd Edition
book

Windows PowerShell Pocket Reference, 2nd Edition

by Lee Holmes
December 2012
Intermediate to advanced
197 pages
3h 50m
English
O'Reilly Media, Inc.
Content preview from Windows PowerShell Pocket Reference, 2nd Edition

Chapter 5. .NET DateTime Formatting

DateTime format strings convert a DateTime object to one of several standard formats, as listed in Table 5-1.

Table 5-1. Standard DateTime format strings

Format specifier

Name

Description

Example

d

Short date

The culture’s short date format.

PS > "{0:d}" -f [DateTime] "01/23/4567"
1/23/4567

D

Long date

The culture’s long date format.

PS > "{0:D}" -f [DateTime] "01/23/4567"
Friday, January 23, 4567

f

Full date/short time

Combines the long date and short time format patterns.

PS > "{0:f}" -f [DateTime] "01/23/4567"
Friday, January 23, 4567 12:00 AM

F

Full date/long time

Combines the long date and long time format patterns.

PS > "{0:F}" -f [DateTime] "01/23/4567"
Friday, January 23, 4567 12:00:00 AM

g

General date/ short time

Combines the short date and short time format patterns.

PS > "{0:g}" -f [DateTime] "01/23/4567"
1/23/4567 12:00 AM

G

General date/long time

Combines the short date and long time format patterns.

PS > "{0:G}" -f [DateTime] "01/23/4567"
1/23/4567 12:00:00 AM

M or m

Month day

The culture’s MonthDay format.

PS > "{0:M}" -f [DateTime] "01/23/4567"
January 23

o

Round-trip date/time

The date formatted with a pattern that guarantees the string (when parsed) will result in the original DateTime again.

PS > "{0:o}" -f [DateTime] "01/23/4567"
4567-01-23T00:00:00.0000000

R or r

RFC1123

The standard RFC1123 format pattern.

PS > "{0:R}" -f [DateTime] "01/23/4567"
Fri, 23 Jan 4567 00:00:00 GMT

s

Sortable

Sortable format pattern. Conforms to ISO 8601 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PowerShell Pocket Reference, 3rd Edition

PowerShell Pocket Reference, 3rd Edition

Lee Holmes

Publisher Resources

ISBN: 9781449363369Errata Page