Search notes:

System.DateTime (struct)

An instance of the System.DateTime represents
Each of these possible point in times is assigned a 64-bit number, called tick, which represents the number of 100-nonosecond intervals between Midnight January 1, 0001 and the point in time the instance of the struct represents.
In PowerShell, the current date-time is returned by the get-date cmdLet.

Creating a DateTime object in PowerShell

A DateTime object can be created in PowerShell like so:
$dt = new-object dateTime 2020,03,15 , 14,53,18
It is also possible to crete a DateTime object with the System.Convert.ToDatetime() method.

String-formatting a DateTime

The ToString() method takes a format string that allows to format the value of a DateTime object.
The following C# example shows a few format strings that are culture-independent:
using System;

class C {

   private static void printFormat(String format) {
      Console.WriteLine("{0,-20}: {1}", format, DateTime.Now.ToString(format));
   }

   static void Main() {
      printFormat("yyyy-MM-dd");   
      printFormat("HH:mm:ss"  );   
      printFormat("r"         ); // RFC 1123
      printFormat("s"         ); // sortable
      printFormat("U"         ); // universal
   }
}
//   possible Output:
//
//   yyyy-MM-dd          : 2019-11-09
//   HH:mm:ss            : 20:28:53
//   r                   : Sat, 09 Nov 2019 20:28:53 GMT
//   s                   : 2019-11-09T20:28:53
//   u                   : 2019-11-09 20:28:53Z
Github repository .NET-API, path: /System/DateTime/ToString.cs
In PowerShell,it is possible to format a DateTime object with the -f operator.
$dt = new-object dateTime 2020,08,28 , 22,23,24

write-host "created date time refers to $('{0:yyyy-MM-dd HH:mm:ss}' -f $dt)"
Github repository .NET-API, path: /System/DateTime/format.ps1

Converting a UTC string to a local time

In PowerShell, a string that describes a point in time in UTC format can be converted to a local time like so:
$utc   =  '2021-10-25T13:23:08.0966497Z'
$local = ([dateTime] $utc).ToLocalTime()

write-host $local

Relation to file times

Ticks that are used in System.DateTime are related to another Microsoft specific representation of point in times: file times.
A file time measures a point in time as the number of 100-nanosecond intervals («ticks») that have elapsed since midnight, January 1601, UTC (as opposed to counting such intervals starting in the Year 1).
System.DateTime offers four methods to convert between file times and DateTimes.

Removing time information from a DateTime object

With .NET 6, time related information (hours, minutes, seconds) can be «removed» from a DateTime object:
var dt = DateOnly.FromDateTime(dt_hms);

Fields, properties and methods

Add()
AddDays()
AddHours()
AddMilliseconds()
AddMinutes()
AddMonths()
AddSeconds()
AddTicks()
AddYears()
Compare()
CompareTo()
Date
Day
DayOfWeek
DayOfYear
DaysInMonth()
Equals()
FromBinary()
FromFileTime()
FromFileTimeUtc()
FromOADate()
GetDateTimeFormats()
GetHashCode()
GetTypeCode()
Hour
IsDaylightSavingTime()
IsLeapYear()
Kind indicates whether the time represented by this instance is based on local time, UTC or neither.
MaxValue one of the three fields
Millisecond
Minute
MinValue one of the three fields
Month
Now
Parse()
ParseExact()
Second
SpecifyKind()
Subtract()
Ticks
TimeOfDay
ToBinary()
Today A static property that evaluates to a DateTime that represents today.
ToFileTime()
ToFileTimeUtc()
ToLocalTime()
ToLongDateString()
ToLongTimeString()
ToOADate()
ToShortDateString()
ToShortTimeString()
ToString()
ToUniversalTime()
TryFormat()
TryParse()
TryParseExact()
UnixEpoch one of the three fields
UtcNow
Year

See also

System.DateTime offers methods to convert between a DateTime and OLE Automation dates.
System.DateTimeOffset, System.TimeSpan, System.TimeZoneInfo, System.Diagnostics.Stopwatch
The PowerShell type accelerator for System.Datetime is [datetime].
The Perl module DateTime
The SQL Server data types that are suited best to store a DateTime are datetime or datetime2 or smalldatetime.

Index