Functions/GenXdev.Console/UtcNow.ps1
|
############################################################################### <# .SYNOPSIS Gets the current UTC (Coordinated Universal Time) date and time. .DESCRIPTION Returns the current UTC date and time as a System.DateTime object. This function provides a standardized way to retrieve UTC time across different systems and time zones. The returned DateTime object can be used for timestamp synchronization, logging, and cross-timezone operations. .LICENSE Copyright (C) 2026 René Vaessen / GenXdev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. .EXAMPLE $currentUtc = UtcNow Returns the current UTC time as a DateTime object. .EXAMPLE $timestamp = (UtcNow).ToString("yyyy-MM-dd HH:mm:ss") Gets the current UTC time and formats it as a string. #> function UtcNow { [CmdletBinding()] [OutputType([System.DateTime])] param() begin { # log function execution for debugging purposes Microsoft.PowerShell.Utility\Write-Verbose 'Starting UtcNow function execution' } process { # retrieve the current utc time using .net datetime for precision Microsoft.PowerShell.Utility\Write-Verbose 'Retrieving current UTC datetime' [DateTime]::UtcNow } end { } } |